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

  • Home
  • SEARCH
  • 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 6721811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:22:23+00:00 2026-05-26T09:22:23+00:00

I have an activity in which i am supposed to use TabBar , I

  • 0

I have an activity in which i am supposed to use TabBar , I have already extended this activity from other class so i cant extend TabActivity.

I read one solution to use tabHost.setup() HERE.

But i am not able to execute that way.getting NullPointerException.

If someone can help me with proper example.

Here is the XML file

   <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mytabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >


    <LinearLayout android:id="@+id/LinearLayout01"
        android:orientation="vertical" android:layout_height="fill_parent"
        android:layout_width="fill_parent">

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

        <FrameLayout android:id="@android:id/tabcontent" 
            android:layout_height="fill_parent" android:layout_width="fill_parent"></FrameLayout>

    </LinearLayout>

</TabHost>

Here is the Java File.

public class TabActivityActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    TabHost tabHost = (TabHost) findViewById(R.id.mytabhost);
    tabHost.setup();
  }

}

Here is the Log Cat Error

10-20 15:21:05.196: ERROR/AndroidRuntime(6265): Uncaught handler: thread main exiting due to uncaught exception
10-20 15:21:05.206: ERROR/AndroidRuntime(6265): java.lang.NullPointerException
10-20 15:21:05.206: ERROR/AndroidRuntime(6265): at android.widget.TabHost.dispatchWindowFocusChanged(TabHost.java:295)
10-20 15:21:05.206: ERROR/AndroidRuntime(6265): at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661)
10-20 15:21:05.206: ERROR/AndroidRuntime(6265): at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661)
10-20 15:21:05.206: ERROR/AndroidRuntime(6265): at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661)
10-20 15:21:05.206: ERROR/AndroidRuntime(6265): at android.view.ViewRoot.handleMessage(ViewRoot.java:1819)
10-20 15:21:05.206: ERROR/AndroidRuntime(6265): at android.os.Handler.dispatchMessage(Handler.java:99)
10-20 15:21:05.206: ERROR/AndroidRuntime(6265): at android.os.Looper.loop(Looper.java:123)
10-20 15:21:05.206: ERROR/AndroidRuntime(6265): at android.app.ActivityThread.main(ActivityThread.java:4363)
10-20 15:21:05.206: ERROR/AndroidRuntime(6265): at java.lang.reflect.Method.invokeNative(Native Method)
10-20 15:21:05.206: ERROR/AndroidRuntime(6265): at java.lang.reflect.Method.invoke(Method.java:521)
10-20 15:21:05.206: ERROR/AndroidRuntime(6265): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
10-20 15:21:05.206: ERROR/AndroidRuntime(6265): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
10-20 15:21:05.206: ERROR/AndroidRuntime(6265): at dalvik.system.NativeStart.main(Native Method)

On adding second tab its giving following error

10-20 16:46:23.361: ERROR/AndroidRuntime(1471): Uncaught handler: thread main exiting due to uncaught exception
10-20 16:46:23.381: ERROR/AndroidRuntime(1471): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tab/com.tab.TabActivityActivity}: java.lang.RuntimeException: Could not create tab content because could not find view with id 2130903041
10-20 16:46:23.381: ERROR/AndroidRuntime(1471): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
10-20 16:46:23.381: ERROR/AndroidRuntime(1471): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
10-20 16:46:23.381: ERROR/AndroidRuntime(1471): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
10-20 16:46:23.381: ERROR/AndroidRuntime(1471): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
10-20 16:46:23.381: ERROR/AndroidRuntime(1471): at android.os.Handler.dispatchMessage(Handler.java:99)
10-20 16:46:23.381: ERROR/AndroidRuntime(1471): at android.os.Looper.loop(Looper.java:123)
10-20 16:46:23.381: ERROR/AndroidRuntime(1471): at android.app.ActivityThread.main(ActivityThread.java:4363)
10-20 16:46:23.381: ERROR/AndroidRuntime(1471): at java.lang.reflect.Method.invokeNative(Native Method)
10-20 16:46:23.381: ERROR/AndroidRuntime(1471): at java.lang.reflect.Method.invoke(Method.java:521)
10-20 16:46:23.381: ERROR/AndroidRuntime(1471): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
10-20 16:46:23.381: ERROR/AndroidRuntime(1471): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
10-20 16:46:23.381: ERROR/AndroidRuntime(1471): at dalvik.system.NativeStart.main(Native Method)
10-20 16:46:23.381: ERROR/AndroidRuntime(1471): Caused by: java.lang.RuntimeException: Could not create tab content because could not find view with id 2130903041
10-20 16:46:23.381: ERROR/AndroidRuntime(1471): at android.widget.TabHost$ViewIdContentStrategy.(TabHost.java:587)
10-20 16:46:23.381: ERROR/AndroidRuntime(1471): at android.widget.TabHost$ViewIdContentStrategy.(TabHost.java:578)
10-20 16:46:23.381: ERROR/AndroidRuntime(1471): at android.widget.TabHost$TabSpec.setContent(TabHost.java:435)
10-20 16:46:23.381: ERROR/AndroidRuntime(1471): at com.tab.TabActivityActivity.onCreate(TabActivityActivity.java:22)
10-20 16:46:23.381: ERROR/AndroidRuntime(1471): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-20 16:46:23.381: ERROR/AndroidRuntime(1471): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
10-20 16:46:23.381: ERROR/AndroidRuntime(1471): … 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-05-26T09:22:24+00:00Added an answer on May 26, 2026 at 9:22 am

    Put at least one tab content into it

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        TabHost tabHost = (TabHost) findViewById(R.id.mytabhost);
        tabHost.setup();
    
        TabSpec tab1 = tabHost.newTabSpec("TAB_1");
        tab1.setIndicator("Tab 1");
        tab1.setContent(R.id.tab1);
        tabHost.addTab(tab1);
    
        //tab 2 etc...
        TabSpec tab2 = tabHost.newTabSpec("TAB_2");
        tab2.setIndicator("Tab 2");
        tab2.setContent(R.id.tab2);
        tabHost.addTab(tab2);
    }
    

    and in the xml:

    <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/mytabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    
    
        <LinearLayout android:id="@+id/LinearLayout01"
            android:orientation="vertical" android:layout_height="fill_parent"
            android:layout_width="fill_parent">
    
            <TabWidget android:id="@android:id/tabs" 
                android:layout_height="wrap_content" android:layout_width="fill_parent"></TabWidget>
    
            <FrameLayout android:id="@android:id/tabcontent" 
                android:layout_height="fill_parent" android:layout_width="fill_parent">
                <LinearLayout android:layout_width="fill_parent"
                    android:layout_height="fill_parent" android:id="@+id/tab1">
                    <!-- tab 1 content goes here -->
                </LinearLayout>
                <LinearLayout android:layout_width="fill_parent"
                    android:layout_height="fill_parent" android:id="@+id/tab2">
                    <!-- tab 2 content goes here -->
                </LinearLayout>
    
            </FrameLayout>
    
        </LinearLayout>
    
    </TabHost>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Service class and an main Acitivity class which is supposed to
I have a home page activity that I got from an example, which works
i have an application in which i have a UI activity which is supposed
I have an activity which is going to switch around between several views, and
I have a activity which has a button and 2 autocomplete widget. for the
I have an Activity which shows a welcome message if started for the first
I have an activity which shows some List entries. When I click on a
I have an activity which needs to make two remote server calls. The first
I have an activity which uses two Loaders. Each of them returns different type
I have an activity which consists of a ListView . The problem is that

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.