2013-01-17 60 views
6

我有一个问题:片段安卓:片段无法实例片段

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

的XML布局不工作:

<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" /> 

这工作虽然:

<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" /> 

知道为什么? 谢谢!

当从Android Eclipse创建新项目时,它的设置来自SettingsActivty,并且仅在平板电脑大小为AVD时打开。

已将此添加到AndroidManifest:

<intent-filter> 
      <action android:name="android.intent.action.MAIN"/> 
      <category android:name="android.intent.category.LAUNCHER"/> 
    </intent-filter>) 
+0

我有同样的问题,任何人都知道发生了什么事? – Wang

回答

7

它不工作,因为${packageName}${activityClass}应该与你的包和活动所取代。

你现在正在做。从文档中检查这个example

+1

谢谢!我认为在那里有什么魔法:-)从工具中生成,如果他们在代码中留言或者修复代码,这会很好... – powder366

+0

我认为这是一个错误。 – powder366