Kooper
Kooper

Reputation: 715

A Tab Exception Message

06-14 00:21:30.398: ERROR/AndroidRuntime(332): Caused by: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'

what it means? I've already given the id for tabhost.And I can see the id in R.java.

Here is the .xml:

<TabHost
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="5dp">

        <TabWidget
            android:id="@+id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <FrameLayout
            android:id="@+id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp" />
    </LinearLayout>
</TabHost>

Upvotes: 0

Views: 3680

Answers (3)

Jignesh Ansodariya
Jignesh Ansodariya

Reputation: 12695

you should remove the statement

tabHost = (TabHost)findViewById(***********);

and add

tabHost = getTabHost();

Upvotes: 1

brmcmaho
brmcmaho

Reputation: 409

The problem here is the line "android:id="@+id/tabhost". The "@+" character means you are directing android to look in your local R file. This is fine in most cases if you have defined an id there, but not when you are looking for a built in id from the OS. The rule with extending TabActivity is you have to give the TabHost the "magic" android tabhost id. This means you need a line like "android:id=@android:id/tabhost" (note the lack of the "@+").

Upvotes: 2

CommonsWare
CommonsWare

Reputation: 1007359

If you are going to use TabActivity, you need to use @android:id/tabhost as the android:id value of your TabHost.

Upvotes: 6

Related Questions