Android fragment: fragment Unable to instantiate fragment

I have a problem with:

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

The xml layout does not work:

 <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!

An example comes from SettingsActivty when creating a new project with Android Eclipse and it is broken only by the size of the AVD tablet.

Added this to AndroidManifest:

  <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter>) 
+6
source share
1 answer

It does not work because ${packageName} and ${activityClass} must be replaced by your package and activity.

You are doing it right now. Check example documentation.

+7
source

All Articles