我正在使用Holoeverywhere图书馆。我应该优先选择用户选择日期。我把这个偏好放在我的文件中,就像这样
<org.holoeverywhere.preference.DatePreference
android:key="preference_birth_date"
android:summary="@string/preference_birth_date"
android:title="@string/preference_birth_date" />
当我启动首选项屏幕时,我收到以下错误:
01-17 23:11:10.719: E/AndroidRuntime(26307): FATAL EXCEPTION: main
01-17 23:11:10.719: E/AndroidRuntime(26307): java.lang.RuntimeException: Unable to start activity ComponentInfo{dev.gauss.istrabike/dev.gauss.istrabike.settings.UserProfilePreferencesActivity}: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Long
01-17 23:11:10.719: E/AndroidRuntime(26307): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2092)
01-17 23:11:10.719: E/AndroidRuntime(26307): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2117)
01-17 23:11:10.719: E/AndroidRuntime(26307): at android.app.ActivityThread.access$700(ActivityThread.java:134)
01-17 23:11:10.719: E/AndroidRuntime(26307): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1218)
01-17 23:11:10.719: E/AndroidRuntime(26307): at android.os.Handler.dispatchMessage(Handler.java:99)
01-17 23:11:10.719: E/AndroidRuntime(26307): at android.os.Looper.loop(Looper.java:137)
01-17 23:11:10.719: E/AndroidRuntime(26307): at android.app.ActivityThread.main(ActivityThread.java:4867)
01-17 23:11:10.719: E/AndroidRuntime(26307): at java.lang.reflect.Method.invokeNative(Native Method)
01-17 23:11:10.719: E/AndroidRuntime(26307): at java.lang.reflect.Method.invoke(Method.java:511)
01-17 23:11:10.719: E/AndroidRuntime(26307): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
01-17 23:11:10.719: E/AndroidRuntime(26307): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
01-17 23:11:10.719: E/AndroidRuntime(26307): at dalvik.system.NativeStart.main(Native Method)
01-17 23:11:10.719: E/AndroidRuntime(26307): Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Long
01-17 23:11:10.719: E/AndroidRuntime(26307): at android.app.SharedPreferencesImpl.getLong(SharedPreferencesImpl.java:228)
01-17 23:11:10.719: E/AndroidRuntime(26307): at org.holoeverywhere.preference._SharedPreferencesImpl_XML.getLong(_SharedPreferencesImpl_XML.java:263)
01-17 23:11:10.719: E/AndroidRuntime(26307): at org.holoeverywhere.preference._SharedPreferencesImpl_XML.getLong(_SharedPreferencesImpl_XML.java:263)
01-17 23:11:10.719: E/AndroidRuntime(26307): at org.holoeverywhere.preference.Preference.getPersistedLong(Preference.java:412)
01-17 23:11:10.719: E/AndroidRuntime(26307): at org.holoeverywhere.preference.DatePreference.onSetInitialValue(DatePreference.java:144)
01-17 23:11:10.719: E/AndroidRuntime(26307): at org.holoeverywhere.preference.Preference.dispatchSetInitialValue(Preference.java:178)
01-17 23:11:10.719: E/AndroidRuntime(26307): at org.holoeverywhere.preference.Preference.onAttachedToHierarchy(Preference.java:607)
01-17 23:11:10.719: E/AndroidRuntime(26307): at org.holoeverywhere.preference.PreferenceGroup.addPreference(PreferenceGroup.java:74)
01-17 23:11:10.719: E/AndroidRuntime(26307): at org.holoeverywhere.preference.PreferenceGroup.addItemFromInflater(PreferenceGroup.java:40)
01-17 23:11:10.719: E/AndroidRuntime(26307): at org.holoeverywhere.preference.PreferenceGroup.addItemFromInflater(PreferenceGroup.java:1)
01-17 23:11:10.719: E/AndroidRuntime(26307): at org.holoeverywhere.app.GenericInflater.rInflate(GenericInflater.java:262)
01-17 23:11:10.719: E/AndroidRuntime(26307): at org.holoeverywhere.app.GenericInflater.rInflate(GenericInflater.java:263)
01-17 23:11:10.719: E/AndroidRuntime(26307): at org.holoeverywhere.app.GenericInflater.inflate(GenericInflater.java:194)
01-17 23:11:10.719: E/AndroidRuntime(26307): at org.holoeverywhere.app.GenericInflater.inflate(GenericInflater.java:164)
01-17 23:11:10.719: E/AndroidRuntime(26307): at org.holoeverywhere.app.GenericInflater.inflate(GenericInflater.java:158)
01-17 23:11:10.719: E/AndroidRuntime(26307): at org.holoeverywhere.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:384)
01-17 23:11:10.719: E/AndroidRuntime(26307): at org.holoeverywhere.preference.PreferenceActivity.addPreferencesFromResource(PreferenceActivity.java:284)
01-17 23:11:10.719: E/AndroidRuntime(26307): at dev.gauss.istrabike.settings.UserProfilePreferencesActivity.onCreate(UserProfilePreferencesActivity.java:68)
01-17 23:11:10.719: E/AndroidRuntime(26307): at android.app.Activity.performCreate(Activity.java:5047)
01-17 23:11:10.719: E/AndroidRuntime(26307): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
01-17 23:11:10.719: E/AndroidRuntime(26307): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2056)
01-17 23:11:10.719: E/AndroidRuntime(26307): ... 11 more
当我从XML文件中删除首选项时,一切正常。我只在XML中设置了我在代码中没有做任何事情的偏好。
答案 0 :(得分:1)
您的商店中有一个键preference_birth_date
的字符串值。它是由先前使用EditTextPreference
使用相同密钥引起的。只需清除应用数据或将密钥更改为其他内容即可。
答案 1 :(得分:0)
看起来你尚未实现的类'ComponentInfo'在将字符串转换为long时遇到问题,查看该类的代码或覆盖'ComponentInfo'的任何子类中的'onCreate'方法。