ClassCastException in PreferenceActivity

前端 未结 3 1405
野的像风
野的像风 2020-12-20 20:07

I am trying to get an example from the Android 2 Application Development book by Reto Meier to work (page 202). As per the instructions I have created a userpreferences.xml

相关标签:
3条回答
  • 2020-12-20 20:16

    I had the same problem - the user preference data from the previous example in the book used different data types when saving the preference data.

    The solution is to simply check the 'clear user data' checkbox when starting the AVD to get rid of the old user preferences.

    0 讨论(0)
  • 2020-12-20 20:19

    If you change a preference type from ListPreference to CheckBoxPreference, whilst reusing the same key, then this bug will happen.

    The Android framework will store some default data in your app's shared_prefs/preferences.xml file. These old values will be in the old format (such as Int or String, for ListPreference) instead of Boolean (for CheckBoxPreference).

    WHen you load your preference activity, it will load this XML file automatically, and cause this crash.

    The solution is to just edit this stored XML preference file (shared_prefs/preferences.xml) and remove the old values. Or just delete that XML file.

    0 讨论(0)
  • 2020-12-20 20:33

    Perhaps you are running into this? http://code.google.com/p/android/issues/detail?id=2096.

    [update] Per the comment, yes make all of your arrays of type string-array and you should be good.

    0 讨论(0)
提交回复
热议问题