Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fragment android:fragment Unable to instantiate fragment

Tags:

android

I have problem with:

android.app.Fragment$InstantiationException: Unable to instantiate fragment ${packageName}.${activityClass}$GeneralPreferenceFragment

The xml layout not working:

<preference-headers xmlns:android="http://schemas.android.com/apk/res/android" >

<!-- These settings headers are only used on tablets. -->

<header
    android:fragment="${packageName}.${activityClass}$GeneralPreferenceFragment"
    android:title="@string/pref_header_general" />

This works though:

<preference-headers xmlns:android="http://schemas.android.com/apk/res/android" >

<!-- These settings headers are only used on tablets. -->

<header
    android:fragment="com.example.b.SettingsActivity$GeneralPreferenceFragment"
    android:title="@string/pref_header_general" />

Any idea why? Thanks!

Example comes from SettingsActivty when creating a new project from Android Eclipse and it only breaks on a tablet size AVD.

Added this to the AndroidManifest:

    <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>)
like image 383
powder366 Avatar asked Jan 17 '13 14:01

powder366


1 Answers

It's not working because ${packageName} and ${activityClass} should be replaced with your package and activity.

You are doing it right now. Check this example from the documentation.

like image 66
nachoplaza Avatar answered Sep 23 '22 06:09

nachoplaza