FC when adding another EditTextPreference
I have a working XML preferences, but when i add it another EditTextPreference the preference activity keeps FCing:
<PreferenceCategory android:title="Prochain vidange">
<EditTextPreference
android:name="Prochain vidange"
android:summary="Prochain vidange:"
android:defaultValue=""
android:numeric="integer|decimal"
android:title="Prochain vidange:"
android:key="proch" />
</PreferenceCategory>
Whole XML:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="Kilométrage/prix">
<EditTextPreference
android:name="KM après vidange"
android:summary="Kilométrage après vidange:"
android:defaultValue=""
android:numeric="integer|decimal"
android:title="Kilométrage après vidange:"
android:key="km" />
<EditTextPreference
android:name="Prix du vidange"
android:summary="Prix du vidange:"
android:defaultValue=""
android:numeric="integer|decimal"
android:title="Prix du vidange:"
android:key="prix_vidange" />
</PreferenceCategory>
<PreferenceCategory android:title="Huile Moteur">
<ListPreference
android:title="Huile Moteur"
android:summary="L'huile moteur mis est de..."
android:key="listPref_huile_moteur"
android:entries="@array/huile_moteur"
android:entryValues="@array/huile_return"
android:negativeButtonText="Annuler" />
</PreferenceCategory>
<PreferenceCategory android:title="Filtre changés">
<CheckBoxPreference
android:key="huile"
android:title="Filtre à air"
android:defaultValue="false"
android:summary="Avez vous changez le filtre à huile?" />
<CheckBoxPreference
android:key="air"
android:title="Filtre à huile"
android:defaultValue="false"
android:summary="Avez vous changez le filtre à air?" />
<CheckBoxPreference
android:key="carburant"
android:title="Filtre carburant"
android:defaultValue="false"
android:summary="Avez vous changez le filtre à essence/diesel ?" />
</PreferenceCategory>
<PreferenceCategory android:title="Notifications">
<CheckBoxPreference
android:key="notif"
android:title="Notifications"
android:defaultValue="false"
android:summary="Voulez vous recevoir des rappels de vidange?" />
<ListPreference
android:title="Fréquence notifications"
android:summary="Recevoir des notifications..."
android:key="listPref_notif"
android:entries="@array/notif"
android:entryValues="@array/notif_return"
android:negativeButtonText="Annuler" />
</PreferenceCategory>
<PreferenceCategory android:title="Prochain vidange">
<EditTextPreference
android:name="Prochain vidange"
android:summary="Prochain vidange:"
android:defaultValue=""
android:numeric="integer|decimal"
android:title="Prochain vidange:"
android:key="proch" />
</PreferenceCategory>
</PreferenceScreen>
logcat :
08-16 14:23:15.639: ERROR/AndroidRuntime(880): FATAL EXCEPTION: main
08-16 14:23:15.639: ERROR/AndroidRuntime(880): java.lang.RuntimeException: Unable to start activity ComponentInfo{carburant.android.com/carburant.android.com.Vidange}: java.lang.ClassCastException: java.lang.Integer
08-16 14:23:15.639: ERROR/AndroidRuntime(880): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
08-16 14:23:15.639: ERROR/AndroidRuntime(880): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-16 14:23:15.639: ERROR/AndroidRuntime(880): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-16 14:23:15.639: ERROR/AndroidRuntime(880): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-16 14:23:15.639: ERROR/AndroidRuntime(880): at android.os.Handler.dispatchMessage(Handler.java:99)
08-16 14:23:开发者_开发知识库15.639: ERROR/AndroidRuntime(880): at android.os.Looper.loop(Looper.java:123)
08-16 14:23:15.639: ERROR/AndroidRuntime(880): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-16 14:23:15.639: ERROR/AndroidRuntime(880): at java.lang.reflect.Method.invokeNative(Native Method)
08-16 14:23:15.639: ERROR/AndroidRuntime(880): at java.lang.reflect.Method.invoke(Method.java:507)
08-16 14:23:15.639: ERROR/AndroidRuntime(880): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-16 14:23:15.639: ERROR/AndroidRuntime(880): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-16 14:23:15.639: ERROR/AndroidRuntime(880): at dalvik.system.NativeStart.main(Native Method)
08-16 14:23:15.639: ERROR/AndroidRuntime(880): Caused by: java.lang.ClassCastException: java.lang.Integer
08-16 14:23:15.639: ERROR/AndroidRuntime(880): at android.app.ContextImpl$SharedPreferencesImpl.getString(ContextImpl.java:2810)
08-16 14:23:15.639: ERROR/AndroidRuntime(880): at android.preference.Preference.getPersistedString(Preference.java:1256)
08-16 14:23:15.639: ERROR/AndroidRuntime(880): at android.preference.EditTextPreference.onSetInitialValue(EditTextPreference.java:154)
08-16 14:23:15.639: ERROR/AndroidRuntime(880): at android.preference.Preference.dispatchSetInitialValue(Preference.java:1172)
08-16 14:23:15.639: ERROR/AndroidRuntime(880): at android.preference.Preference.onAttachedToHierarchy(Preference.java:984)
08-16 14:23:15.639: ERROR/AndroidRuntime(880): at android.preference.PreferenceGroup.addPreference(PreferenceGroup.java:156)
08-16 14:23:15.639: ERROR/AndroidRuntime(880): at android.preference.PreferenceGroup.addItemFromInflater(PreferenceGroup.java:97)
08-16 14:23:15.639: ERROR/AndroidRuntime(880): at android.preference.PreferenceGroup.addItemFromInflater(PreferenceGroup.java:38)
08-16 14:23:15.639: ERROR/AndroidRuntime(880): at android.preference.GenericInflater.rInflate(GenericInflater.java:488)
08-16 14:23:15.639: ERROR/AndroidRuntime(880): at android.preference.GenericInflater.rInflate(GenericInflater.java:493)
08-16 14:23:15.639: ERROR/AndroidRuntime(880): at android.preference.GenericInflater.inflate(GenericInflater.java:326)
08-16 14:23:15.639: ERROR/AndroidRuntime(880): at android.preference.GenericInflater.inflate(GenericInflater.java:263)
08-16 14:23:15.639: ERROR/AndroidRuntime(880): at android.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:251)
08-16 14:23:15.639: ERROR/AndroidRuntime(880): at android.preference.PreferenceActivity.addPreferencesFromResource(PreferenceActivity.java:262)
08-16 14:23:15.639: ERROR/AndroidRuntime(880): at carburant.android.com.Vidange.onCreate(Vidange.java:45)
08-16 14:23:15.639: ERROR/AndroidRuntime(880): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-16 14:23:15.639: ERROR/AndroidRuntime(880): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-16 14:23:15.639: ERROR/AndroidRuntime(880): ... 11 more
08-16 14:23:15.688: WARN/ActivityManager(61): Force finishing activity carburant.android.com/.Acceuil
What could be the problem with this strange FC ? Thank you.
Example array:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="notif">
<item>Chaque jour</item>
<item>Chaque semaine</item>
<item>Chaque mois</item>
</string-array>
<string-array name="notif_return">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>
</resources>
Are you setting one of your arrays to an integer-array? (android:entries="@array/blah")
There is a known bug you have to use string-array for xml preferences sorry!
http://code.google.com/p/android/issues/detail?id=2096
EDIT
Also possible is your setting your EditTextPreference to of type Integer but your setting the default value of "" which could be a string.
精彩评论