发布版本中的ClassNotFoundException

时间:2011-10-26 14:55:30

标签: android

我正在获取自定义DialogPreference类的ClassNotFoundExption,但只能在发布版本之后。我非常适合调试版本。

这是堆栈跟踪:

10-26 16:29:08.521: E/AndroidRuntime(20593): FATAL EXCEPTION: main
10-26 16:29:08.521: E/AndroidRuntime(20593): java.lang.RuntimeException: Unable to start activity ComponentInfo{path.to.my.app.de/path.to.my.app.preferences.Preferences}: android.view.InflateException: Binary XML file line #6: Error inflating class path.to.my.app.preferences.SeekBarPreference
10-26 16:29:08.521: E/AndroidRuntime(20593):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2787)
10-26 16:29:08.521: E/AndroidRuntime(20593):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2803)
10-26 16:29:08.521: E/AndroidRuntime(20593):    at android.app.ActivityThread.access$2300(ActivityThread.java:135)
10-26 16:29:08.521: E/AndroidRuntime(20593):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136)
10-26 16:29:08.521: E/AndroidRuntime(20593):    at android.os.Handler.dispatchMessage(Handler.java:99)
10-26 16:29:08.521: E/AndroidRuntime(20593):    at android.os.Looper.loop(Looper.java:144)
10-26 16:29:08.521: E/AndroidRuntime(20593):    at android.app.ActivityThread.main(ActivityThread.java:4937)
10-26 16:29:08.521: E/AndroidRuntime(20593):    at java.lang.reflect.Method.invokeNative(Native Method)
10-26 16:29:08.521: E/AndroidRuntime(20593):    at java.lang.reflect.Method.invoke(Method.java:521)
10-26 16:29:08.521: E/AndroidRuntime(20593):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-26 16:29:08.521: E/AndroidRuntime(20593):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-26 16:29:08.521: E/AndroidRuntime(20593):    at dalvik.system.NativeStart.main(Native Method)
10-26 16:29:08.521: E/AndroidRuntime(20593): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class path.to.my.app.preferences.SeekBarPreference
10-26 16:29:08.521: E/AndroidRuntime(20593):    at android.preference.GenericInflater.createItemFromTag(GenericInflater.java:441)
10-26 16:29:08.521: E/AndroidRuntime(20593):    at android.preference.GenericInflater.rInflate(GenericInflater.java:481)
10-26 16:29:08.521: E/AndroidRuntime(20593):    at android.preference.GenericInflater.rInflate(GenericInflater.java:493)
10-26 16:29:08.521: E/AndroidRuntime(20593):    at android.preference.GenericInflater.inflate(GenericInflater.java:326)
10-26 16:29:08.521: E/AndroidRuntime(20593):    at android.preference.GenericInflater.inflate(GenericInflater.java:263)
10-26 16:29:08.521: E/AndroidRuntime(20593):    at android.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:254)
10-26 16:29:08.521: E/AndroidRuntime(20593):    at android.preference.PreferenceActivity.addPreferencesFromResource(PreferenceActivity.java:268)
10-26 16:29:08.521: E/AndroidRuntime(20593):    at path.to.my.app.preferences.Preferences.onCreate(Unknown Source)
10-26 16:29:08.521: E/AndroidRuntime(20593):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1069)
10-26 16:29:08.521: E/AndroidRuntime(20593):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751)
10-26 16:29:08.521: E/AndroidRuntime(20593):    ... 11 more
10-26 16:29:08.521: E/AndroidRuntime(20593): Caused by: java.lang.ClassNotFoundException: path.to.my.app.preferences.SeekBarPreference in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/path.to.my.app.de-1.apk]
10-26 16:29:08.521: E/AndroidRuntime(20593):    at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
10-26 16:29:08.521: E/AndroidRuntime(20593):    at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
10-26 16:29:08.521: E/AndroidRuntime(20593):    at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
10-26 16:29:08.521: E/AndroidRuntime(20593):    at android.preference.GenericInflater.createItem(GenericInflater.java:375)
10-26 16:29:08.521: E/AndroidRuntime(20593):    at android.preference.GenericInflater.createItemFromTag(GenericInflater.java:430)
10-26 16:29:08.521: E/AndroidRuntime(20593):    ... 20 more

在堆栈跟踪中调用的xml文件是:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" android:key="screen">
  <PreferenceCategory android:title="@string/pref.title" android:key="cat1" android:order="1">
    <path.to.my.app.preferences.SeekBarPreference android:title="@string/perimeter.head" android:key="myapp.perimeter" android:defaultValue="30" android:text=" km" android:max="80" min="5" android:progress="0"/>
    <CheckBoxPreference android:key="myapp.saveFav" android:enabled="true" android:title="@string/fav.save.title" android:summary="@string/fav.save"></CheckBoxPreference>
  </PreferenceCategory>
    <PreferenceCategory android:title="@string/pref.personal" android:order="2">
    <EditTextPreference android:title="@string/search.customerNumber" android:key="myapp.wizard" android:inputType="textCapCharacters" android:maxLength="7"></EditTextPreference>
    <EditTextPreference android:title="@string/reservation.firstName" android:key="myapp.firstName" android:inputType="textCapWords|textPersonName"></EditTextPreference>
    <EditTextPreference android:title="@string/reservation.lastName" android:key="myapp.lastName" android:inputType="textCapWords|textPersonName"></EditTextPreference>
    <EditTextPreference android:title="@string/reservation.street" android:key="myapp.street" android:inputType="textCapWords|textPostalAddress"></EditTextPreference>
    <EditTextPreference android:title="@string/reservation.zip" android:key="myapp.zip" android:inputType="textCapWords|textPostalAddress"></EditTextPreference>
    <EditTextPreference android:title="@string/reservation.city" android:key="myapp.city" android:inputType="textCapWords"></EditTextPreference>
    <EditTextPreference android:title="@string/reservation.phone" android:key="myapp.phone" android:inputType="phone"></EditTextPreference>
</PreferenceCategory>
<PreferenceCategory android:order="3">
    <EditTextPreference android:title="@string/search.awdNumber" android:key="myapp.awd" android:inputType="textCapCharacters" android:maxLength="6">                    </EditTextPreference>
    <EditTextPreference android:title="@string/costControl.label" android:key="myapp.costControl" android:inputType="textCapWords" android:maxLength="15"></EditTextPreference>
    </PreferenceCategory>
</PreferenceScreen>

对于发布版本,我正在使用ProGuard,并且已经有一行

-keep public class path.to.my.app.preferences.SeekBarPreference

在配置文件中。

对此有任何有用的提示吗?

1 个答案:

答案 0 :(得分:0)

我找到了解决方案(可能不是最好的?)。我添加了

-keep class * extends android.preference.DialogPreference { 
    public <init>(android.content.Context); 
    public <init>(android.content.Context, android.util.AttributeSet); 
    public <init>(android.content.Context, android.util.AttributeSet, int); 
    public void set*(...); 
}

到proguard.cfg。

感谢Blundell。