Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8010543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:45:59+00:00 2026-06-04T18:45:59+00:00

I am making a tab app using this tutorial . When I run my

  • 0

I am making a tab app using this tutorial. When I run my app on device it gives me Force close message. Here is my main activity code and my logcat is below. I have no idea where am I making mistake. here is the code

public class TabLayoutActivity extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Resources res = getResources(); // Resource object to get Drawables
    TabHost tabHost = getTabHost();  // The activity TabHost
    TabHost.TabSpec spec;  // Resusable TabSpec for each tab
    Intent intent;  // Reusable Intent for each tab

    //Artist Tab
    intent = new Intent(this, Artists.class);
    spec = tabHost.newTabSpec("artists").setIndicator("Artist", res.getDrawable(R.drawable.tab_icon)).setContent(intent);
    tabHost.addTab(spec);

  //Songs
    intent = new Intent(this, Songs.class);
    spec = tabHost.newTabSpec("songs").setIndicator("Songs", res.getDrawable(R.drawable.tab_icon)).setContent(intent);
    tabHost.addTab(spec);

  //Albums
    intent = new Intent(this, Album.class);
    spec = tabHost.newTabSpec("artists").setIndicator("Artist", res.getDrawable(R.drawable.tab_icon)).setContent(intent);
    tabHost.addTab(spec);

    tabHost.setCurrentTab(1);
}
}

here is my logcat

05-28 19:16:51.421: D/dalvikvm(15189): GC_EXTERNAL_ALLOC freed 43K, 50% free 2725K/5379K, external 0K/0K, paused 33ms
05-28 19:16:51.441: D/AndroidRuntime(15189): Shutting down VM
05-28 19:16:51.441: W/dalvikvm(15189): threadid=1: thread exiting with uncaught exception (group=0x4001e578)
05-28 19:16:51.451: E/AndroidRuntime(15189): FATAL EXCEPTION: main
05-28 19:16:51.451: E/AndroidRuntime(15189): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.zafar.tablayout/com.zafar.tablayout.TabLayoutActivity}: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'
05-28 19:16:51.451: E/AndroidRuntime(15189):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
05-28 19:16:51.451: E/AndroidRuntime(15189):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
05-28 19:16:51.451: E/AndroidRuntime(15189):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-28 19:16:51.451: E/AndroidRuntime(15189):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
05-28 19:16:51.451: E/AndroidRuntime(15189):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-28 19:16:51.451: E/AndroidRuntime(15189):    at android.os.Looper.loop(Looper.java:130)
05-28 19:16:51.451: E/AndroidRuntime(15189):    at android.app.ActivityThread.main(ActivityThread.java:3691)
05-28 19:16:51.451: E/AndroidRuntime(15189):    at java.lang.reflect.Method.invokeNative(Native Method)
05-28 19:16:51.451: E/AndroidRuntime(15189):    at java.lang.reflect.Method.invoke(Method.java:507)
05-28 19:16:51.451: E/AndroidRuntime(15189):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
05-28 19:16:51.451: E/AndroidRuntime(15189):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
05-28 19:16:51.451: E/AndroidRuntime(15189):    at dalvik.system.NativeStart.main(Native Method)
05-28 19:16:51.451: E/AndroidRuntime(15189): Caused by: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'
05-28 19:16:51.451: E/AndroidRuntime(15189):    at android.app.TabActivity.onContentChanged(TabActivity.java:105)
05-28 19:16:51.451: E/AndroidRuntime(15189):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:218)
05-28 19:16:51.451: E/AndroidRuntime(15189):    at android.app.Activity.setContentView(Activity.java:1663)
05-28 19:16:51.451: E/AndroidRuntime(15189):    at com.zafar.tablayout.TabLayoutActivity.onCreate(TabLayoutActivity.java:14)
05-28 19:16:51.451: E/AndroidRuntime(15189):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-28 19:16:51.451: E/AndroidRuntime(15189):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
05-28 19:16:51.451: E/AndroidRuntime(15189):    ... 11 more
05-28 19:16:57.256: I/Process(15189): Sending signal. PID: 15189 SIG: 9

Update

Here is my tabhost in main.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"
android:orientation="vertical" >

Second Update

Logcat after changing tabHost to tabhost

05-28 19:47:56.271: I/Process(16575): Sending signal. PID: 16575 SIG: 9
05-28 19:47:58.381: D/dalvikvm(16782): GC_EXTERNAL_ALLOC freed 46K, 50% free 2725K/5379K, external 0K/0K, paused 20ms
05-28 19:47:58.411: D/AndroidRuntime(16782): Shutting down VM
05-28 19:47:58.411: W/dalvikvm(16782): threadid=1: thread exiting with uncaught exception (group=0x4001e578)
05-28 19:47:58.411: E/AndroidRuntime(16782): FATAL EXCEPTION: main
05-28 19:47:58.411: E/AndroidRuntime(16782): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.zafar.tablayout/com.zafar.tablayout.TabLayoutActivity}: java.lang.RuntimeException: Your TabHost must have a TabWidget whose id attribute is 'android.R.id.tabs'
05-28 19:47:58.411: E/AndroidRuntime(16782):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
05-28 19:47:58.411: E/AndroidRuntime(16782):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
05-28 19:47:58.411: E/AndroidRuntime(16782):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-28 19:47:58.411: E/AndroidRuntime(16782):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
05-28 19:47:58.411: E/AndroidRuntime(16782):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-28 19:47:58.411: E/AndroidRuntime(16782):    at android.os.Looper.loop(Looper.java:130)
05-28 19:47:58.411: E/AndroidRuntime(16782):    at android.app.ActivityThread.main(ActivityThread.java:3691)
05-28 19:47:58.411: E/AndroidRuntime(16782):    at java.lang.reflect.Method.invokeNative(Native Method)
05-28 19:47:58.411: E/AndroidRuntime(16782):    at java.lang.reflect.Method.invoke(Method.java:507)
05-28 19:47:58.411: E/AndroidRuntime(16782):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
05-28 19:47:58.411: E/AndroidRuntime(16782):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
05-28 19:47:58.411: E/AndroidRuntime(16782):    at dalvik.system.NativeStart.main(Native Method)
05-28 19:47:58.411: E/AndroidRuntime(16782): Caused by: java.lang.RuntimeException: Your TabHost must have a TabWidget whose id attribute is 'android.R.id.tabs'
05-28 19:47:58.411: E/AndroidRuntime(16782):    at android.widget.TabHost.setup(TabHost.java:114)
05-28 19:47:58.411: E/AndroidRuntime(16782):    at android.widget.TabHost.setup(TabHost.java:163)
05-28 19:47:58.411: E/AndroidRuntime(16782):    at android.app.TabActivity.onContentChanged(TabActivity.java:109)
05-28 19:47:58.411: E/AndroidRuntime(16782):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:218)
05-28 19:47:58.411: E/AndroidRuntime(16782):    at android.app.Activity.setContentView(Activity.java:1663)
05-28 19:47:58.411: E/AndroidRuntime(16782):    at com.zafar.tablayout.TabLayoutActivity.onCreate(TabLayoutActivity.java:14)
05-28 19:47:58.411: E/AndroidRuntime(16782):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-28 19:47:58.411: E/AndroidRuntime(16782):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
05-28 19:47:58.411: E/AndroidRuntime(16782):    ... 11 more
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T18:46:02+00:00Added an answer on June 4, 2026 at 6:46 pm

    In your main.xml, what is the ID of the TabHost?

    It must be android:id="@android:id/tabhost".

    Edit

    Your TabWidget must be defined as:

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

    It’s actually quite easy to see from the logcat: “Your TabHost must have a TabWidget whose id attribute is ‘android.R.id.tabs'”.

    It would be easier if you posted your entire xml layout file, so we can see all possible errors.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a tab bar iphone app and I wanted to have an animated
I making an app and im currently optimizing it to Samsung Galaxy Tab. I
I'm making an RSS app. In my Add Feed tab there is a UIWebView
I'm making this app with a tableview and stuff. I want to make a
I'm making Android app that has this database in it: public void onCreate(SQLiteDatabase db)
I'm making an app with interface builder using storyboarding. I want to have a
I'm making a simple facebook canvas app (page tab) with PHP, that posts something
i'm making app based on tab bar with two tabs. My problem is that
I'm making a silverlight app that when the user does a mouse-over some tab
I'm in the process of making an Android 3 app that has a tab-based

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.