In my app, I have the values like:
<ListPreference
android:key="font_setting"
android:title="@string/font"
android:summary="%s"
android:entries="@array/font_list"
android:entryValues="@array/font_list_values"
android:dialogTitle="@string/choose_font" />
and the data:
<string-array name="font_list">
<item>"Small"</item>
<item>"Medium"</item>
<item>"Big"</item>
</string-array>
<integer-array name="font_list_values">
<item>1</item>
<item>2</item>
<item>3</item>
</integer-array>
but when I choose one value, the app crashes, there is error:
java.lang.NullPointerException
at android.preference.ListPreference.onDialogClosed(ListPreference.java:264)
I found this is actually a very old issue raised here. And surprisingly, Google just said it is not a bug and there is no fix? Anyone has suggestions?
This is tested in Android version 4.0.
Why not use a string-array and convert to integers later (Integer.valueOf()
), in code:
<string-array name="font_list_values">
<item>1</item>
<item>2</item>
<item>3</item>
</string-array>
This bug seems to get old somehow. I also faced this problem. Just use string-array and parse them with Integer.valueOf()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With