Votre contenu doit avoir un TabHost dont l'attribut id est " android.R.id.tabhost'

J'ai un problème:

Code Java

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

}

Code XML

<?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>

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

Problème

Quelqu'un peut me dire pourquoi il est dit

Votre contenu doit avoir un TabHost dont l'attribut id est " android.R.id.tabhost'

lorsque le android:id = @android:id/tabhost?

Avez-vous essayé la reconstruction de l'ensemble du projet? Parfois, eclipse est un peu bogué dans ces situations
essayez de supprimer votre R fichier et de reconstruction.
J'ai essayé de nettoyer le projet, de le redémarrer et supprimer des R mais rien. J'ai essayé d'utiliser ce code dans une autre application et c'est parti mais ce ne courent pas
Avez-vous plusieurs mise en page des dossiers? Si oui, vérifiez que tous les xml fichier de mise en page ont l'attribut.
Votre commentaire a résolu mon problème! Mon projet utilise une bibliothèque, tous deux avaient main.xml dans la mise en page, et j'ai donc eu l'manquant tabhost erreur. Supprimé le main.xml je n'ai pas besoin, et le problème est résolu, merci 🙂

OriginalL'auteur Matteo Cardellini | 2011-12-16