Ihre Inhalte müssen einen TabHost, deren id-Attribut 'android.R.id.tabhost'
Ich habe ein 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>
Und 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
Kann mir jemand sagen, warum es ist, sagt
Ihre Inhalte müssen einen TabHost, deren id-Attribut 'android.R.id.tabhost'
wenn die android:id = @android:id/tabhost?
- Haben Sie versucht, Umbau das ganze Projekt? Manchmal eclipse ist ein bisschen buggy in solchen Situationen
- löschen Sie den R-Datei-und Umbau.
- Ich versuchte, reinigen Sie das Projekt, starten Sie es, und löschen Sie R aber nichts. Ich habe versucht, diesen code in einer anderen Anwendung, und es ist gestartet, aber in diesem nicht
- Sie haben mehrere layout-Ordner? Wenn ja, überprüfen Sie, dass alle xml-layout-Dateien haben das Attribut.
- Ich habe ein layout-Ordner !
- Dein Kommentar ist mein problem gelöst! Mein Projekt verwendet eine Bibliothek, beide hatten main.xml in layout -, und so bekam ich die fehlenden tabhost Fehler. Gelöscht main.xml brauchte ich nicht und das problem ist behoben, danke 🙂
Du musst angemeldet sein, um einen Kommentar abzugeben.
Reinigen Sie Ihren build aus der
Project > Clean...
- Menü, wenn Sie mit Eclipse. Klingt einfach, aber oft behebt dieses problem.main.xml
?setContentView(R.layout.main);
zusetContentView(R.layout.visualizzaliste);
aber ich denke, du hast das!Glaube ich, dass die Nachricht bedeutet dies:
sollte geändert werden zu:
Einzige, was Sie ändern müssen, ist android:id-Attribut im layout-xml , Es sollte " android:id="@android:id/tabhost" "
Ich hatte das gleiche problem.
Eigentlich habe ich verlängert
TabActivity
fürDaAcquistareActivity
Klasse. Das war der Grund. Ich löste das problem durch die AusweitungDaAcquistareActivity
mitActivity
und nicht mitTabActivity
.Lösung.
Wenn Sie wechseln zu einer neuen Tätigkeit zu überprüfen, es reicht, vielleicht auf reflex kopiert von der primären und es ist eine TabActivity, aber wir müssen Aktivität oder eine andere Aktivität.