为什么壁纸设置出现异常错误?

发布于 2024-12-28 10:59:01 字数 3050 浏览 0 评论 0原文

我给安卓做壁纸,有问题。当我单击设置按钮时,我看到:

01-22 11:50:47.579: E/AndroidRuntime(18421): FATAL EXCEPTION: main
01-22 11:50:47.579: E/AndroidRuntime(18421): java.lang.IllegalStateException: Could not execute method of the activity
01-22 11:50:47.579: E/AndroidRuntime(18421):    at android.view.View$1.onClick(View.java:2154)
01-22 11:50:47.579: E/AndroidRuntime(18421):    at android.view.View.performClick(View.java:2538)
...

我的代码: LiveWallpaperSettings.java:wallpaper_settings.xml:wallpaper.xml

package com.samples;

import android.os.Bundle;
import android.preference.PreferenceActivity;

public class LiveWallpaperSettings extends PreferenceActivity
{
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.wallpaper_settings);
    }
}

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
        android:title="@string/wallpaper_label">
        <PreferenceCategory android:title="General">
                <CheckBoxPreference
                        android:title="Pref01 title"
                        android:summary="Pref01 summary"
                        android:key="pref01" 
                        android:defaultValue="true"
                />
        </PreferenceCategory>
</PreferenceScreen>

清单

<?xml version="1.0" encoding="UTF-8"?>
<wallpaper
        xmlns:android="http://schemas.android.com/apk/res/android"  
        android:thumbnail="@drawable/icon"
        android:description="@string/wallpaper_description"
        android:settingsActivity="com.sample.LiveWallpaperSettings"/>

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.samples"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="7" />
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" 
        android:permission="android.permission.BIND_WALLPAPER">
        <service 
            android:name=".LiveWallpaperService"
            ...

            <intent-filter>
                ...
            </intent-filter>
            <meta-data 
              android:name="android.service.wallpaper" 
              android:resource="@xml/wallpaper" />
        </service>

        <activity 
            android:label="@string/wallpaper_label"
            android:name=".LiveWallpaperSettings"
            android:theme="@android:style/Theme.Light.WallpaperSettings"
            android:exported="true"
            android:icon="@drawable/icon">
        </activity>
    </application>
</manifest>

LiveWallpaperService 不使用任何首选项。 我忘记写什么了? 请帮忙!

I do wallpaper to android and have problem. When I click settings button I see:

01-22 11:50:47.579: E/AndroidRuntime(18421): FATAL EXCEPTION: main
01-22 11:50:47.579: E/AndroidRuntime(18421): java.lang.IllegalStateException: Could not execute method of the activity
01-22 11:50:47.579: E/AndroidRuntime(18421):    at android.view.View$1.onClick(View.java:2154)
01-22 11:50:47.579: E/AndroidRuntime(18421):    at android.view.View.performClick(View.java:2538)
...

My code:
LiveWallpaperSettings.java:

package com.samples;

import android.os.Bundle;
import android.preference.PreferenceActivity;

public class LiveWallpaperSettings extends PreferenceActivity
{
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.wallpaper_settings);
    }
}

wallpaper_settings.xml:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
        android:title="@string/wallpaper_label">
        <PreferenceCategory android:title="General">
                <CheckBoxPreference
                        android:title="Pref01 title"
                        android:summary="Pref01 summary"
                        android:key="pref01" 
                        android:defaultValue="true"
                />
        </PreferenceCategory>
</PreferenceScreen>

wallpaper.xml:

<?xml version="1.0" encoding="UTF-8"?>
<wallpaper
        xmlns:android="http://schemas.android.com/apk/res/android"  
        android:thumbnail="@drawable/icon"
        android:description="@string/wallpaper_description"
        android:settingsActivity="com.sample.LiveWallpaperSettings"/>

Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.samples"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="7" />
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" 
        android:permission="android.permission.BIND_WALLPAPER">
        <service 
            android:name=".LiveWallpaperService"
            ...

            <intent-filter>
                ...
            </intent-filter>
            <meta-data 
              android:name="android.service.wallpaper" 
              android:resource="@xml/wallpaper" />
        </service>

        <activity 
            android:label="@string/wallpaper_label"
            android:name=".LiveWallpaperSettings"
            android:theme="@android:style/Theme.Light.WallpaperSettings"
            android:exported="true"
            android:icon="@drawable/icon">
        </activity>
    </application>
</manifest>

LiveWallpaperService dont use any Preference.
What I forgot to write?
Help please!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

没有心的人 2025-01-04 10:59:01

包名在wallpaper.xml上是错误的:

android:settingsActivity="com.sampleS.LiveWallpaperSettings"

Package name is wrong on wallpaper.xml:

android:settingsActivity="com.sampleS.LiveWallpaperSettings"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文