Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'
Asked Answered
O

5

8

I have a problem:

Java Code

public class VisualizzaListaActivity extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    TabHost tabHost = getTabHost();  // The activity TabHost
    TabHost.TabSpec spec;  // Reusable TabSpec for each tab
    Intent intent;  // Reusable Intent for each tab

    // Create an Intent to launch an Activity for the tab (to be reused)
    intent = new Intent().setClass(this, DaAcquistareActivity.class);

    // Initialize a TabSpec for each tab and add it to the TabHost
    spec = tabHost.newTabSpec("daAcquistare").setIndicator("Da Acquistare").setContent(intent);
    tabHost.addTab(spec);

    // Do the same for the other tabs
    intent = new Intent().setClass(this, AcquistatiActivity.class);
    spec = tabHost.newTabSpec("acquistati").setIndicator("Acquistati").setContent(intent);
    tabHost.addTab(spec);

    tabHost.setCurrentTab(0);
}

}

XML code

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"   <-------------- It's 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="@android:id/tabs"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content" />
    <FrameLayout
       android:id="@android:id/tabcontent"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       android:padding="5dp" />
</LinearLayout>
</TabHost>

And LogCat

12-16 15:26:22.519: E/AndroidRuntime(8262): java.lang.RuntimeException: Unable to start activity ComponentInfo{android.smile.matteo.spesaPRO/android.smile.matteo.spesaPRO.VisualizzaListaActivity}: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'             
12-16 15:26:22.519: E/AndroidRuntime(8262): Caused by: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'
12-16 15:26:22.519: E/AndroidRuntime(8262):         at android.smile.matteo.spesaPRO.VisualizzaListaActivity.onCreate(VisualizzaListaActivity.java:13)

Problem

Someone can tell me why it's says

Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'

when the android:id = @android:id/tabhost?

Obtuse answered 16/12, 2011 at 18:20 Comment(5)
Have you tried rebuilding the whole project? Sometimes eclipse is a bit buggy in those situationsMae
try deleting your R file and rebuilding.Matrimony
I tried to clean the project, restart it, and delete R but nothing. I have tried to use this code in another application and it's started but in this dont runObtuse
Do you have multiple layout folders? If so, check that every xml layout file have the attribute.Sonja
@LadaRaider Your comment solved my problem! My project uses a library, both had main.xml in layout, and so I got the missing tabhost error. Deleted the main.xml I didn't need and the problem is fixed, thanks :)Cither
J
7

Try cleaning your build from the Project > Clean... menu if you are using Eclipse. Sounds simple but often fixes this problem.

Janicejanicki answered 16/12, 2011 at 18:37 Comment(3)
Is your xml file named main.xml?Janicejanicki
Change setContentView(R.layout.main); to setContentView(R.layout.visualizzaliste); but I guess you got that!Janicejanicki
i'm a very big idiot !!! Thanks very much !!! i have concentrated my a attention on the xml file and i don't have see this... Thank you very much yetObtuse
B
20

I believe the message means this:

     <TabHost android:id="@+id/tabhost"

should be changed to:

     <TabHost android:id="@android:id/tabhost"
Breadboard answered 22/6, 2012 at 6:57 Comment(1)
I had to use: android:id="@android:id/tabhost" without the *Wristwatch
J
7

Try cleaning your build from the Project > Clean... menu if you are using Eclipse. Sounds simple but often fixes this problem.

Janicejanicki answered 16/12, 2011 at 18:37 Comment(3)
Is your xml file named main.xml?Janicejanicki
Change setContentView(R.layout.main); to setContentView(R.layout.visualizzaliste); but I guess you got that!Janicejanicki
i'm a very big idiot !!! Thanks very much !!! i have concentrated my a attention on the xml file and i don't have see this... Thank you very much yetObtuse
T
2

Only thing you need to change is android:id attribute in layout xml , It should be " android:id="@android:id/tabhost" "

Teakettle answered 8/3, 2013 at 4:26 Comment(0)
W
1

I had the same problem. Actually I extended TabActivity for DaAcquistareActivity class. This was the reason. I solved the problem by extending DaAcquistareActivity with Activity and not with TabActivity.

Wallywalnut answered 22/5, 2015 at 10:0 Comment(0)
B
0

Solution. If you're switching to a new Activity check it extends, perhaps on reflex copied from the primary, and there is a TabActivity, but we need Activity or other activity.

Beene answered 25/6, 2017 at 19:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.