Android.view.InflateException: binary line of XML file # 4: error inflating class SwitchPreference

I try to read the settings of my application and I get this error:

Settings Activity:

public class Settings extends PreferenceActivity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); try { addPreferencesFromResource(R.xml.prefs); } catch (Exception ex) { Log.e("errorSettings", Log.getStackTraceString(ex)); } } } 

Preferences XML File:

 <?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" > <PreferenceCategory android:title="General"> <SwitchPreference android:title="Downloader" android:defaultValue="true" android:key="useDownloader" android:summary="Enable to use" /> </PreferenceCategory> </PreferenceScreen> 

and in the application manifest, I installed this:

 <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="15" /> 

and the first error I get:

 android.view.InflateException: Binary XML file line #4: Error inflating class SwitchPreference 

Thanx upfront.

+4
source share
1 answer

SwitchPreference was added at API level 14. You cannot use it in earlier versions of Android. Since you are trying to support a return to API level 9, you can:

  • Use another preferred XML for earlier versions, using CheckBoxPreference instead of SwitchPreference or

  • Just use CheckBoxPreference and drop the SwitchPreference now

+14
source

All Articles