ClassNotFoundException 搜索栏首选项

发布于 2024-12-15 05:06:49 字数 2987 浏览 1 评论 0原文

我正在尝试在我的动态壁纸设置中实现搜索栏首选项。问题是我不断收到 ClassNotFoundException

我创建了一个子类(可以在此处查看)来创建搜索栏然后将以下内容添加到我的 wall_settings.xml

<custom.android.mypackage.SeekBarPreference 
    android:title="XXXXXXXXX"
    android:summary="XXXXXXXXXXX"
    android:key="duration"
    android:dialogMessage="Something duration"
    android:defaultValue="5"
    android:text=" minutes"
    android:max="100"
    />

我的 SeekBarPreference.java 类与我的主 Activity 位于同一包中。我需要在清单文件中添加一些内容吗?

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

<uses-feature android:name="android.software.live_wallpaper" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
 <uses-permission android:name="android.permission.SET_WALLPAPER_HINTS"/>
<application android:icon="@drawable/icon" android:label="@string/app_name">
        <service 
        android:name=".MainActivity"
        android:enabled="true"
        android:icon="@drawable/icon"
        android:label="@string/service_name"
        android:permission="android.permission.BIND_WALLPAPER">
        <intent-filter android:priority="1" >
            <action android:name="android.service.wallpaper.WallpaperService" />
        </intent-filter>
        <meta-data 
            android:name="android.service.wallpaper" 
            android:resource="@xml/wallpaper" />
    </service>
     <activity android:exported="true"
        android:label="@string/wallpaper_settings"            
        android:name=".WallpaperSettings"/> 
  <activity
        android:name=".SeekBarPreference" 
android:label="@string/wallpaper_settings" /> 
</application>


11-11 12:32:37.308: ERROR/AndroidRuntime(8419):  
Caused by:java.lang.ClassNotFoundException: custom.android.mypackage.SeekBarPreference in loader dalvik.system.PathClassLoader[/data/app/custom.android.mypackage-2.apk]
11-11 12:32:37.308: ERROR/AndroidRuntime(8419):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
11-11 12:32:37.308: ERROR/AndroidRuntime(8419):     at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
11-11 12:32:37.308: ERROR/AndroidRuntime(8419):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
11-11 12:32:37.308: ERROR/AndroidRuntime(8419):     at android.preference.GenericInflater.createItem(GenericInflater.java:375)
11-11 12:32:37.308: ERROR/AndroidRuntime(8419):     at android.preference.GenericInflater.createItemFromTag(GenericInflater.java:430)
11-11 12:32:37.308: ERROR/AndroidRuntime(8419):     ... 20 more

I'm trying to implement a seek bar preference into my live wallpaper settings. The problem is that I keep getting a ClassNotFoundException.

I created a subclass (which can be viewed here) to create the seekbar then added the following to my wallpaper_settings.xml

<custom.android.mypackage.SeekBarPreference 
    android:title="XXXXXXXXX"
    android:summary="XXXXXXXXXXX"
    android:key="duration"
    android:dialogMessage="Something duration"
    android:defaultValue="5"
    android:text=" minutes"
    android:max="100"
    />

My SeekBarPreference.java class is in the same package as my main Activity. Is there something I need to add to my manifest file?

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

<uses-feature android:name="android.software.live_wallpaper" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
 <uses-permission android:name="android.permission.SET_WALLPAPER_HINTS"/>
<application android:icon="@drawable/icon" android:label="@string/app_name">
        <service 
        android:name=".MainActivity"
        android:enabled="true"
        android:icon="@drawable/icon"
        android:label="@string/service_name"
        android:permission="android.permission.BIND_WALLPAPER">
        <intent-filter android:priority="1" >
            <action android:name="android.service.wallpaper.WallpaperService" />
        </intent-filter>
        <meta-data 
            android:name="android.service.wallpaper" 
            android:resource="@xml/wallpaper" />
    </service>
     <activity android:exported="true"
        android:label="@string/wallpaper_settings"            
        android:name=".WallpaperSettings"/> 
  <activity
        android:name=".SeekBarPreference" 
android:label="@string/wallpaper_settings" /> 
</application>

11-11 12:32:37.308: ERROR/AndroidRuntime(8419):  
Caused by:java.lang.ClassNotFoundException: custom.android.mypackage.SeekBarPreference in loader dalvik.system.PathClassLoader[/data/app/custom.android.mypackage-2.apk]
11-11 12:32:37.308: ERROR/AndroidRuntime(8419):     at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
11-11 12:32:37.308: ERROR/AndroidRuntime(8419):     at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
11-11 12:32:37.308: ERROR/AndroidRuntime(8419):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
11-11 12:32:37.308: ERROR/AndroidRuntime(8419):     at android.preference.GenericInflater.createItem(GenericInflater.java:375)
11-11 12:32:37.308: ERROR/AndroidRuntime(8419):     at android.preference.GenericInflater.createItemFromTag(GenericInflater.java:430)
11-11 12:32:37.308: ERROR/AndroidRuntime(8419):     ... 20 more

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

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

发布评论

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

评论(1

携君以终年 2024-12-22 05:06:49

SeekBarPreference 是 customView 而不是 Activity 。所以

 <activity
        android:name=".SeekBarPreference" 
android:label="@string/wallpaper_settings" /> 

找不到它。将其从菜单中删除

SeekBarPreference is customView not activity . so

 <activity
        android:name=".SeekBarPreference" 
android:label="@string/wallpaper_settings" /> 

can not find it . remove it from menifest

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