Skip to content Skip to sidebar Skip to footer

How To Use Preferences In Android Support Library V7 Rev23?

In my app using support library v7 I want to add a preference screen. Since Google provides absolutely no documentation on that subject I have looked up a post found elsewhere here

Solution 1:

Your logcat hints at the error: XML file line #11: Error inflating class fragment -- the suspicious line there seems to be name=".FragmentPreferences" which you probably wanted to be android:name=".FragmentPreferences". Since you already have that, just delete the erroneous line :)

<fragmentandroid:name=".FragmentPreferences"android:tag=".FragmentPreferences"android:layout_width="match_parent"android:layout_height="match_parent" />

UPDATE: if that doesn't work, then the other blatantly obvious error is in the android:namevalue. It should be:

android:name="com.example.testandroidsupportv7.FragmentPreferences"

or whatever is YOUR actual path to the FragmentPreferences class.

I even built your project on my end, it took all of less than 5 minutes to create, test, and confirm the error; I got exactly the same error as you, when I fixed android:name it builds just fine. Screenshot:

enter image description here

I hope you will apologize to everyone for your behaviour... it is NOT how to go about getting help from people on SO.

UPDATE 2: partial logcat from my build, with the erroneous android:name value:

11-07 14:00:24.742 26456-26456/com.example.testandroidsupportv7 E/AndroidRuntime: FATAL EXCEPTION: main
11-07 14:00:24.742 26456-26456/com.example.testandroidsupportv7 E/AndroidRuntime: Process: com.example.testandroidsupportv7, PID: 26456
11-07 14:00:24.742 26456-26456/com.example.testandroidsupportv7 E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.testandroidsupportv7/com.example.testandroidsupportv7.ActivityPreferences}: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
11-07 14:00:24.742 26456-26456/com.example.testandroidsupportv7 E/AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2345)
11-07 14:00:24.742 26456-26456/com.example.testandroidsupportv7 E/AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2405)
11-07 14:00:24.742 26456-26456/com.example.testandroidsupportv7 E/AndroidRuntime:     at android.app.ActivityThread.access$800(ActivityThread.java:155)
11-07 14:00:24.742 26456-26456/com.example.testandroidsupportv7 E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1323)
...
11-07 14:00:24.742 26456-26456/com.example.testandroidsupportv7 E/AndroidRuntime:   Suppressed: java.lang.ClassNotFoundException: Invalid name: .FragmentPreferences

dependencies:

compile'com.android.support:support-v4:23.1.0'compile'com.android.support:appcompat-v7:23.1.0'compile'com.android.support:preference-v7:23.1.0'compile'com.android.support:design:23.1.0'

Please don't ask me to now find a 2.3.5 device to test for you.

Post a Comment for "How To Use Preferences In Android Support Library V7 Rev23?"