I'm trying a really simple PreferenceActivity and it's working fine with EditTextPreference but it always throws this error when I add a ListPreference (line 16 is the ListPreference line):
11-06 15:15:02.746: E/AndroidRuntime(11607): FATAL EXCEPTION: main 11-06 15:15:02.746: E/AndroidRuntime(11607): java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.mtcbrasilia.aa/br.com.mtcbrasilia.aa.PreferencesActivity}: android.view.InflateException: Binary XML file line #16: Error inflating class java.lang.reflect.Constructor 11-06 15:15:02.746: E/AndroidRuntime(11607): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2247) 11-06 15:15:02.746: E/AndroidRuntime(11607): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2297) 11-06 15:15:02.746: E/AndroidRuntime(11607): at android.app.ActivityThread.access$700(ActivityThread.java:152) 11-06 15:15:02.746: E/AndroidRuntime(11607): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1282) 11-06 15:15:02.746: E/AndroidRuntime(11607): at android.os.Handler.dispatchMessage(Handler.java:99) 11-06 15:15:02.746: E/AndroidRuntime(11607): at android.os.Looper.loop(Looper.java:137) 11-06 15:15:02.746: E/AndroidRuntime(11607): at android.app.ActivityThread.main(ActivityThread.java:5328) 11-06 15:15:02.746: E/AndroidRuntime(11607): at java.lang.reflect.Method.invokeNative(Native Method) 11-06 15:15:02.746: E/AndroidRuntime(11607): at java.lang.reflect.Method.invoke(Method.java:511) 11-06 15:15:02.746: E/AndroidRuntime(11607): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102) 11-06 15:15:02.746: E/AndroidRuntime(11607): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869) 11-06 15:15:02.746: E/AndroidRuntime(11607): at dalvik.system.NativeStart.main(Native Method) 11-06 15:15:02.746: E/AndroidRuntime(11607): Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class java.lang.reflect.Constructor 11-06 15:15:02.746: E/AndroidRuntime(11607): at android.preference.GenericInflater.createItem(GenericInflater.java:397) 11-06 15:15:02.746: E/AndroidRuntime(11607): at android.preference.GenericInflater.onCreateItem(GenericInflater.java:417) 11-06 15:15:02.746: E/AndroidRuntime(11607): at android.preference.GenericInflater.createItemFromTag(GenericInflater.java:428) 11-06 15:15:02.746: E/AndroidRuntime(11607): at android.preference.GenericInflater.rInflate(GenericInflater.java:481) 11-06 15:15:02.746: E/AndroidRuntime(11607): at android.preference.GenericInflater.inflate(GenericInflater.java:326) 11-06 15:15:02.746: E/AndroidRuntime(11607): at android.preference.GenericInflater.inflate(GenericInflater.java:263) 11-06 15:15:02.746: E/AndroidRuntime(11607): at android.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:269) 11-06 15:15:02.746: E/AndroidRuntime(11607): at android.preference.PreferenceActivity.addPreferencesFromResource(PreferenceActivity.java:1531) 11-06 15:15:02.746: E/AndroidRuntime(11607): at br.com.mtcbrasilia.aa.PreferencesActivity.onCreate(PreferencesActivity.java:12) 11-06 15:15:02.746: E/AndroidRuntime(11607): at android.app.Activity.performCreate(Activity.java:5250) 11-06 15:15:02.746: E/AndroidRuntime(11607): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097) 11-06 15:15:02.746: E/AndroidRuntime(11607): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211) 11-06 15:15:02.746: E/AndroidRuntime(11607): ... 11 more 11-06 15:15:02.746: E/AndroidRuntime(11607): Caused by: java.lang.reflect.InvocationTargetException 11-06 15:15:02.746: E/AndroidRuntime(11607): at java.lang.reflect.Constructor.constructNative(Native Method) 11-06 15:15:02.746: E/AndroidRuntime(11607): at java.lang.reflect.Constructor.newInstance(Constructor.java:417) 11-06 15:15:02.746: E/AndroidRuntime(11607): at android.preference.GenericInflater.createItem(GenericInflater.java:383) 11-06 15:15:02.746: E/AndroidRuntime(11607): ... 22 more 11-06 15:15:02.746: E/AndroidRuntime(11607): Caused by: java.lang.NullPointerException 11-06 15:15:02.746: E/AndroidRuntime(11607): at android.content.res.AssetManager.getResourceTextArray(AssetManager.java:214) 11-06 15:15:02.746: E/AndroidRuntime(11607): at android.content.res.Resources.getTextArray(Resources.java:1273) 11-06 15:15:02.746: E/AndroidRuntime(11607): at android.content.res.TypedArray.getTextArray(TypedArray.java:629) 11-06 15:15:02.746: E/AndroidRuntime(11607): at android.preference.ListPreference.(ListPreference.java:50) 11-06 15:15:02.746: E/AndroidRuntime(11607): ... 25 more
Here's my res/xml/preferences.xml:
<?xml version="1.0" encoding="utf-8"?>
<EditTextPreference
android:title="test"
android:summary="summary test"
android:key="testKey"/>
<ListPreference android:key="languagePref"
android:entries="@array/menu_pref_language_titles"
android:summary="bla bla"
android:entryValues="@array/menu_pref_language_codes"
android:title="@string/pref_language" />
My PreferencesActivity:
public class PreferencesActivity extends PreferenceActivity {
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
My strings.xml:
<string name="pref_language">Language:</string>
<string name="pref_language_default">default</string>
<string-array name="menu_pref_language">
<item>Device default</item>
<item>English</item>
<item>Portuguese</item>
</string-array>
<string-array name="menu_pref_language_codes">
<item>default</item>
<item>en</item>
<item>pt</item>
</string-array>
And my Manifest:
<activity
android:name=".PreferencesActivity"
android:label="@string/action_settings"
android:launchMode="standard"
>
</activity>
My target sdks are 11 to 18 (for now) and it's not working on 18 (I'm having problems with my emulators). I know I could use PreferenceFragment but I intend to target older sdks later.
Any thoughts?
In the preference file you have:
android:entries="@array/menu_pref_language_titles"
in the strings file you have
name="menu_pref_language"