我使用的是主 - 詳細信息流的類和xml佈局,這在創建新項目時可用,並列列表和詳細視圖。不過,我收到此錯誤:InflateException引起的<fragment>沒有綁定類的標籤
E/AndroidRuntime( 724): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.TrueFalse/com.TrueFalse.news.NewsModule}: android.view.InflateException: Binary XML file line #14: Error inflating class fragment
E/AndroidRuntime( 724): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1736)
E/AndroidRuntime( 724): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1752)
E/AndroidRuntime( 724): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
E/AndroidRuntime( 724): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:993)
E/AndroidRuntime( 724): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 724): at android.os.Looper.loop(Looper.java:126)
E/AndroidRuntime( 724): at android.app.ActivityThread.main(ActivityThread.java:3997)
E/AndroidRuntime( 724): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 724): at java.lang.reflect.Method.invoke(Method.java:491)
E/AndroidRuntime( 724): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
E/AndroidRuntime( 724): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
E/AndroidRuntime( 724): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 724): Caused by: android.view.InflateException: Binary XML file line #14: Error inflating class fragment
E/AndroidRuntime( 724): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:688)
E/AndroidRuntime( 724): at android.view.LayoutInflater.rInflate(LayoutInflater.java:724)
E/AndroidRuntime( 724): at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
E/AndroidRuntime( 724): at android.view.LayoutInflater.inflate(LayoutInflater.java:391)
E/AndroidRuntime( 724): at android.view.LayoutInflater.inflate(LayoutInflater.java:347)
E/AndroidRuntime( 724): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:224)
E/AndroidRuntime( 724): at android.app.Activity.setContentView(Activity.java:1777)
E/AndroidRuntime( 724): at com.TrueFalse.news.NewsModule.onCreate(NewsModule.java:19)
E/AndroidRuntime( 724): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
E/AndroidRuntime( 724): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1700)
E/AndroidRuntime( 724): ... 11 more
E/AndroidRuntime( 724): Caused by: java.lang.NullPointerException
E/AndroidRuntime( 724): at java.lang.VMClassLoader.findLoadedClass(Native Method)
E/AndroidRuntime( 724): at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:390)
E/AndroidRuntime( 724): at java.lang.ClassLoader.loadClass(ClassLoader.java:538)
E/AndroidRuntime( 724): at java.lang.ClassLoader.loadClass(ClassLoader.java:508)
E/AndroidRuntime( 724): at android.support.v4.app.Fragment.instantiate(Fragment.java:391)
E/AndroidRuntime( 724): at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
E/AndroidRuntime( 724): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
E/AndroidRuntime( 724): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:660)
E/AndroidRuntime( 724): ... 20 more
我懷疑這事做的事實,我沒有設置任何機器人:名字=「」或者類=「」,這可以解釋堆棧跟蹤,但是上面提到的模板除了改變一些名字外,還有相同的xml文件。
在跟蹤我的代碼行數是
setContentView(R.layout.news_list_container);
我NewsModule類擴展android.support.v4.app.FragmentActivity。
/res/values-large/refs.xml(圖news_list_container.xml到news_twopane_container.xml,對此我相當肯定發生這種情況,因爲它適用於那些不符合「大型設備罰款:約束。)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- List of layout overrides for screens that can support iPad style views.
This should mirror the other refs.xml file-->
<item name="news_list_container" type="layout">@layout/news_twopane_container</item>
</resources>
/res/layout/news_twopane_container.xml(第14行是
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<fragment
android:id="@+id/news_list_container"
android:name="com.TrueFalse.news.NewsList"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1" />
<fragment
android:id="@+id/news_detail_container"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1" />
</LinearLayout>
你能發表'Fragment'的相關代碼嗎? – 2013-01-23 02:47:17
你叫'setContentView(R.layout.news_list_container);',你可以向我們展示這個XML文件嗎? –
如果你添加了「android:name =」com.TrueFalse.news.DetailsFrgmt「,那會起作用嗎?我只是問,因爲我有同樣的問題,雖然你的回答解決了問題,但我不明白爲什麼我們的第一種方法不起作用 – feresr