2014-01-17 47 views
0

我正在使用Holoeverywhere庫。我應該有一個偏好,用戶選擇一個日期。我把這種偏好在我的文件中像這樣Android Holoeverywhere DatePreference錯誤

<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中設置了偏好,我沒有在代碼中做任何事情。

回答

1

您的商店中有密鑰preference_birth_date的字符串值。它由早前使用相同密鑰使用EditTextPreference引起。只需清除應用數據或將密鑰更改爲其他內容即可。

+0

噢,好的...那有效。非常感謝你......你救了我的生命:) – Tooroop

+0

btw ...當我設置一個onDateSetListener時,在onDateSet()方法中,當我得到月份值時,該值總是比它應該小1。 當我設置1月份的月份值爲0,並且當我設置12月份時,月份值爲11 ...這是預期的行爲嗎? – Tooroop

0

看起來您還沒有實現類的ComponentInfo'與鑄造串地龍的問題,考慮該類或重寫代碼「的onCreate的方法在「ComponentInfo」的任何子類。

+0

我認爲ComponentInfo和這個沒有任何關係:) – Tooroop

相關問題