Fustigador
Fustigador

Reputation: 6459

My TabHost HAS a FrameLayout with that id

This is my code:

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);

In my 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>

I am getting this exception:

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.access$800(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)

             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2313)              at android.app.ActivityThread.access$800(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)

I have tried changing id attribute to "android.R.id.tabcontent". I tried to delete the R class, and of course clean and rebuild. Any help to get rid of this exception in 2015...?

Upvotes: 0

Views: 419

Answers (1)

Vladyslav Matviienko
Vladyslav Matviienko

Reputation: 10871

as the stacktrace says, android:id attribute has to be not @+id/tabcontent, but @android:id/tabcontent

Upvotes: 2

Related Questions