我有一个有效的XML首选项,但当我添加另一个EditTextPreference时,首选项活动会保持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>
整个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
这个奇怪的FC有什么问题? 谢谢。
示例数组:
<?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>
答案 0 :(得分:0)
您是否将其中一个数组设置为整数数组? (机器人:项= “@阵列/嗒嗒”)
对于xml首选项,您必须使用 string-array 来处理已知错误,对不起!
http://code.google.com/p/android/issues/detail?id=2096
编辑
也可以将EditTextPreference设置为Integer类型,但设置默认值“”可能是字符串。