Your content should have TabHost, whose id attribute is 'android.R.id.tabhost'

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 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 he is talking

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

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

+7
source share
5 answers

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

+7
source

I believe the message means the following:

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

should be changed to:

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

The only thing you need to change is the android: id attribute in the xml layout, it should be "android: id =" @android: id / tabhost ""

+2
source

I had the same problem. In fact, I have expanded TabActivity for the DaAcquistareActivity class. That's why. I solved the problem by extending DaAcquistareActivity to Activity , not TabActivity .

+1
source

Decision. If you switch to a new activity check, it expands, possibly with reflection copied from the primary, and there is TabActivity , but we need activity or another action.

0
source

All Articles