Question

Every time I switch over to the preferences activity, I get a run time error that fc my app. I'm trying to learn Android programming, and i managed to resolve the problems i had but after a big amount of time searching for help i can't understand what i'm doing wrong.

This is the code of Settings.java:

package com.wisp.sudokuapp;

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

public class Settings extends PreferenceActivity {
    @SuppressWarnings("deprecation")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.settings);
    }

}

My settings.xml:

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

    <CheckboxPreference
       android:key="hints"
       android:title="@string/settings_hints_title"
       android:summary="@string/settings_hints_summary"
       android:defaultValue="true" />

    <CheckboxPreference
       android:key="music"
       android:title="@string/settings_music_title"
       android:summary="@string/settings_music_summary"
       android:defaultValue="true" />

</PreferenceScreen>

My manifest:

(...)
        <activity android:name="com.wisp.sudokuapp.Settings"
            android:label="@string/settings_title">
        </activity>
(...)

And the Logcat:

03-25 17:22:22.637: W/dalvikvm(440): threadid=1: thread exiting with uncaught exception (group=0x40015560)
03-25 17:22:22.687: E/AndroidRuntime(440): FATAL EXCEPTION: main
03-25 17:22:22.687: E/AndroidRuntime(440): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.wisp.sudokuapp/com.wisp.sudokuapp.Settings}: android.view.InflateException: Binary XML file line #5: Error inflating class CheckboxPreference
03-25 17:22:22.687: E/AndroidRuntime(440):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
03-25 17:22:22.687: E/AndroidRuntime(440):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
03-25 17:22:22.687: E/AndroidRuntime(440):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-25 17:22:22.687: E/AndroidRuntime(440):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
03-25 17:22:22.687: E/AndroidRuntime(440):  at android.os.Handler.dispatchMessage(Handler.java:99)
03-25 17:22:22.687: E/AndroidRuntime(440):  at android.os.Looper.loop(Looper.java:123)
03-25 17:22:22.687: E/AndroidRuntime(440):  at android.app.ActivityThread.main(ActivityThread.java:3683)
03-25 17:22:22.687: E/AndroidRuntime(440):  at java.lang.reflect.Method.invokeNative(Native Method)
03-25 17:22:22.687: E/AndroidRuntime(440):  at java.lang.reflect.Method.invoke(Method.java:507)
03-25 17:22:22.687: E/AndroidRuntime(440):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-25 17:22:22.687: E/AndroidRuntime(440):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-25 17:22:22.687: E/AndroidRuntime(440):  at dalvik.system.NativeStart.main(Native Method)
03-25 17:22:22.687: E/AndroidRuntime(440): Caused by: android.view.InflateException: Binary XML file line #5: Error inflating class CheckboxPreference
03-25 17:22:22.687: E/AndroidRuntime(440):  at android.preference.GenericInflater.createItemFromTag(GenericInflater.java:441)
03-25 17:22:22.687: E/AndroidRuntime(440):  at android.preference.GenericInflater.rInflate(GenericInflater.java:481)
03-25 17:22:22.687: E/AndroidRuntime(440):  at android.preference.GenericInflater.inflate(GenericInflater.java:326)
03-25 17:22:22.687: E/AndroidRuntime(440):  at android.preference.GenericInflater.inflate(GenericInflater.java:263)
03-25 17:22:22.687: E/AndroidRuntime(440):  at android.preference.PreferenceManager.inflateFromResource(PreferenceManager.java:251)
03-25 17:22:22.687: E/AndroidRuntime(440):  at android.preference.PreferenceActivity.addPreferencesFromResource(PreferenceActivity.java:262)
03-25 17:22:22.687: E/AndroidRuntime(440):  at com.wisp.sudokuapp.Settings.onCreate(Settings.java:11)
03-25 17:22:22.687: E/AndroidRuntime(440):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-25 17:22:22.687: E/AndroidRuntime(440):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
03-25 17:22:22.687: E/AndroidRuntime(440):  ... 11 more
03-25 17:22:22.687: E/AndroidRuntime(440): Caused by: java.lang.ClassNotFoundException: android.preference.CheckboxPreference in loader dalvik.system.PathClassLoader[/data/app/com.wisp.sudokuapp-1.apk]
03-25 17:22:22.687: E/AndroidRuntime(440):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
03-25 17:22:22.687: E/AndroidRuntime(440):  at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
03-25 17:22:22.687: E/AndroidRuntime(440):  at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
03-25 17:22:22.687: E/AndroidRuntime(440):  at android.preference.GenericInflater.createItem(GenericInflater.java:375)
03-25 17:22:22.687: E/AndroidRuntime(440):  at android.preference.GenericInflater.onCreateItem(GenericInflater.java:417)
03-25 17:22:22.687: E/AndroidRuntime(440):  at android.preference.GenericInflater.createItemFromTag(GenericInflater.java:428)
03-25 17:22:22.687: E/AndroidRuntime(440):  ... 19 more

I know that the method is obsolete, but I'd like it to work with 2.3.x. To learn android developing i am reading a book, and in the book it seems to work. I found that commenting out the line addPreferencesFromResource will keep the app from crashing, but obviously doesn't load any UI.

I REALLY apreciate your help.

Sorry for my English.

Was it helpful?

Solution

The issue is with a typo in the xml file. Change CheckboxPreference to CheckBoxPreference.

OTHER TIPS

You've got a spelling error. Two, infact. Try:

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

    <CheckBoxPreference
       android:key="hints"
       android:title="@string/settings_hints_title"
       android:summary="@string/settings_hints_summary"
       android:defaultValue="true" />

    <CheckBoxPreference
       android:key="music"
       android:title="@string/settings_music_title"
       android:summary="@string/settings_music_summary"
       android:defaultValue="true" />

</PreferenceScreen>

Android XML is case sensitive, so CheckboxPreference is a different, non existent thing from CheckBoxPreference.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top