我的 TabHost 有一个带有该 ID 的 FrameLayout
My TabHost HAS a FrameLayout with that id
这是我的代码:
tabHost = (FragmentTabHost) findViewById(R.id.tabhost);
tabHost.setup(this, getSupportFragmentManager(), R.id.tabcontent);
tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("Lengüeta 1"),
Tab1.class, null);
tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("Lengüeta 2"),
Tab2.class, null);
tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("Lengüeta 3"),
Tab3.class, null);
在我的 XML:
<android.support.v4.app.FragmentTabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"/>
<FrameLayout
android:id="@+id/tabcontent"
android:layout_width="match_parent"
android:layout_height="0dp"/>
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
我遇到了这个异常:
08:07:22.353 1970-1970/com.infaplic.lpi E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.infaplic.lpi, PID: 1970
java.lang.RuntimeException: Unable to start activity ComponentInfo{my.package/my.package.activities.SwipeActivity}: java.lang.RuntimeException: Your TabHost must have a FrameLayout whose id attribute is 'android.R.id.tabcontent'
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2263)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2313)
at android.app.ActivityThread.access0(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5212)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Your TabHost must have a FrameLayout whose id attribute is 'android.R.id.tabcontent'
at android.widget.TabHost.setup(TabHost.java:163)
at android.support.v4.app.FragmentTabHost.setup(FragmentTabHost.java:197)
at com.infaplic.lpi.activities.SwipeActivity.onCreate(SwipeActivity.java:59)
at android.app.Activity.performCreate(Activity.java:5240)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2227)
在
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2313)
android.app.ActivityThread.access800 美元(ActivityThread.java:144)
在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
在 android.os.Handler.dispatchMessage(Handler.java:106)
在 android.os.Looper.loop(Looper.java:136)
在 android.app.ActivityThread.main(ActivityThread.java:5212)
在 java.lang.reflect.Method.invokeNative(本机方法)
在 java.lang.reflect.Method.invoke(Method.java:515)
在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
在 dalvik.system.NativeStart.main(本机方法)
我试过将 id 属性更改为 "android.R.id.tabcontent"。我试图删除 R class,当然还有清理和重建。对在 2015 年消除此异常有任何帮助...?
正如堆栈跟踪所说,android:id
属性必须不是 @+id/tabcontent
,而是 @android:id/tabcontent
这是我的代码:
tabHost = (FragmentTabHost) findViewById(R.id.tabhost);
tabHost.setup(this, getSupportFragmentManager(), R.id.tabcontent);
tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("Lengüeta 1"),
Tab1.class, null);
tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("Lengüeta 2"),
Tab2.class, null);
tabHost.addTab(tabHost.newTabSpec("tab3").setIndicator("Lengüeta 3"),
Tab3.class, null);
在我的 XML:
<android.support.v4.app.FragmentTabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"/>
<FrameLayout
android:id="@+id/tabcontent"
android:layout_width="match_parent"
android:layout_height="0dp"/>
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
我遇到了这个异常:
08:07:22.353 1970-1970/com.infaplic.lpi E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.infaplic.lpi, PID: 1970
java.lang.RuntimeException: Unable to start activity ComponentInfo{my.package/my.package.activities.SwipeActivity}: java.lang.RuntimeException: Your TabHost must have a FrameLayout whose id attribute is 'android.R.id.tabcontent'
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2263)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2313)
at android.app.ActivityThread.access0(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5212)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Your TabHost must have a FrameLayout whose id attribute is 'android.R.id.tabcontent'
at android.widget.TabHost.setup(TabHost.java:163)
at android.support.v4.app.FragmentTabHost.setup(FragmentTabHost.java:197)
at com.infaplic.lpi.activities.SwipeActivity.onCreate(SwipeActivity.java:59)
at android.app.Activity.performCreate(Activity.java:5240)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2227)
在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2313) android.app.ActivityThread.access800 美元(ActivityThread.java:144) 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246) 在 android.os.Handler.dispatchMessage(Handler.java:106) 在 android.os.Looper.loop(Looper.java:136) 在 android.app.ActivityThread.main(ActivityThread.java:5212) 在 java.lang.reflect.Method.invokeNative(本机方法) 在 java.lang.reflect.Method.invoke(Method.java:515) 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602) 在 dalvik.system.NativeStart.main(本机方法)
我试过将 id 属性更改为 "android.R.id.tabcontent"。我试图删除 R class,当然还有清理和重建。对在 2015 年消除此异常有任何帮助...?
正如堆栈跟踪所说,android:id
属性必须不是 @+id/tabcontent
,而是 @android:id/tabcontent