Search code examples
androideclipseandroid-preferences

PreferenceScreen crashes


I made a PreferenceScreen using res/xml/preferences.xml

<?xml version="1.0" encoding="utf-8"?>
<preferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

    <preferencecategory 

     android:title="@string/pref_lang_setting">

        <listpreference 
            android:key="preflang" 
            android:entries="@array/lang_select_array" 
            android:summary="@string/pref_lang_summary"  
            android:title="@string/pref_lang"
            android:entryValues="@array/lang_select_Values"
            >

        </listpreference>

    </preferencecategory>

</preferenceScreen>

The PreferencesActivity looks like this:

package com.example.mypackage;

import android.os.Bundle;
import android.preference.PreferenceActivity;


public class PreferencesActivity extends PreferenceActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

     addPreferencesFromResource(R.xml.preferences);  // deprecated
    }

}

And this is called from another Activity by using:

case R.id.action_settings:
             Intent i = new Intent(this, PreferencesActivity.class);
             startActivity(i);  
             // startActivityForResult(i, RESULT_SETTINGS);
        break;

When I click to load the PreferencesActivity, the application crashes and I get this error:

05-18 11:39:15.882: W/System.err(29994): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mypackage/com.example.mypackage.PreferencesActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class preferenceScreen

I have searched a lot, but the problem remains.
Any help is appreciated.


Solution

  • Use the proper character casing for PreferenceScreen, PreferenceCategory and ListPreference