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 7778171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:19:48+00:00 2026-06-01T18:19:48+00:00

After searching for a solution I decided to re-ask a question already asked here

  • 0

After searching for a solution I decided to re-ask a question already asked here.

I have a TabHost control, and I need to put it inside other Layout (LinearLayout). I tuck the example that google gives us (http://developer.android.com/resources/tutorials/views/hello-tabwidget.html) and did the same with the only difference that the TabHost is not the root of the layout and the activity class that display the view doesn’t extend TabActivity, but Activity

My xml is this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TabHost android:id="@+id/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="53px"
                android:tabStripEnabled="false" android:layout_margin="1px"
                android:background="#222222" />
            <FrameLayout android:id="@android:id/tabcontent"
                android:layout_width="fill_parent" android:layout_height="fill_parent"
                android:padding="5dp" />
        </LinearLayout>
    </TabHost>
</LinearLayout>

and the java class is this:

public class TabsExampleActivity extends Activity {

    TabHost tabHost;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        initTabs();

    }


    private void initTabs() {
        Resources res = getResources();                     // Resource object to get Drawables
        tabHost = (TabHost) findViewById(R.id.tabhost);     // The activity TabHost

        TabHost.TabSpec spec;                               // Resusable TabSpec for each tab
        Intent intent;                                      // Reusable Intent for each tab        

        intent = new Intent("eu.pkg.tabsExample.BuildingTabActivity");
        spec = tabHost.newTabSpec("text").setIndicator("",
                          res.getDrawable(R.drawable.tab_text_selector))
                      .setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, ClipArtTabActivity.class);
        spec = tabHost.newTabSpec("clipart").setIndicator("",
                          res.getDrawable(R.drawable.tab_clipart_selector))
                      .setContent(intent);
        tabHost.addTab(spec);


        intent = new Intent().setClass(this, FrameSelectorTabActivity.class);
        spec = tabHost.newTabSpec("frame").setIndicator("",
                          res.getDrawable(R.drawable.tab_frame_selector))
                      .setContent(intent);
        tabHost.addTab(spec);



        intent = new Intent().setClass(this, BgSelectorTabActivity.class);
        spec = tabHost.newTabSpec("bg").setIndicator("",
                          res.getDrawable(R.drawable.tab_bg_selector))
                      .setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, BuildingTabActivity.class);
        spec = tabHost.newTabSpec("build").setIndicator("",
                          res.getDrawable(R.drawable.tab_build_selector))
                      .setContent(intent);
        tabHost.addTab(spec);

        tabHost.setCurrentTab(4);
    }
}

If I use as base activity the TabActivity, and I use the TabHost as root, then the code works well, I see the tabs… etc.

The issue appears only if I extend Activity and the error is:

04-11 18:53:38.874: ERROR/AndroidRuntime(32539):
java.lang.RuntimeException: Unable to start activity
ComponentInfo{eu.pkg.tabsExample/eu.pkg.tabsExample.TabsExampleActivity}:
java.lang.NullPointerException

The question is: How to host a TabHost inside a LinearLayout?

Edit:

After changing as suggested in comments, the log cat errors are:

04-11 20:52:01.993: ERROR/imdg81(28747): IsShutDownStarted() 04-11
20:52:01.999: ERROR/SensorManager(28747): registerListener 4:gp2a
Light Sensor delay:240 04-11 20:52:01.999: ERROR/SensorManager(28747):
=======>>>Sensor Thread RUNNING <<<======== 04-11 20:52:02.075: ERROR/imdg81(28747): IsShutDownStarted() 04-11 20:52:02.284:
ERROR/LockPatternKeyguardView(28747): Phone is boot completed. so can
send broadcast message for music player 04-11 20:52:05.507:
ERROR/jdwp(3675): Failed writing handshake bytes: Broken pipe (-1 of
14) 04-11 20:52:05.609: ERROR/AndroidRuntime(3675): FATAL EXCEPTION:
main 04-11 20:52:05.609: ERROR/AndroidRuntime(3675):
java.lang.RuntimeException: Unable to start activity
ComponentInfo{eu.pkg.tabsExample/eu.pkg.tabsExample.TabsExampleActivity}:
java.lang.IllegalStateException: Did you forget to call ‘public void
setup(LocalActivityManager activityGroup)’? 04-11 20:52:05.609:
ERROR/AndroidRuntime(3675): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
04-11 20:52:05.609: ERROR/AndroidRuntime(3675): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-11 20:52:05.609: ERROR/AndroidRuntime(3675): at
android.app.ActivityThread.access$2300(ActivityThread.java:125) 04-11
20:52:05.609: ERROR/AndroidRuntime(3675): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-11 20:52:05.609: ERROR/AndroidRuntime(3675): at
android.os.Handler.dispatchMessage(Handler.java:99) 04-11
20:52:05.609: ERROR/AndroidRuntime(3675): at
android.os.Looper.loop(Looper.java:123) 04-11 20:52:05.609:
ERROR/AndroidRuntime(3675): at
android.app.ActivityThread.main(ActivityThread.java:4627) 04-11
20:52:05.609: ERROR/AndroidRuntime(3675): at
java.lang.reflect.Method.invokeNative(Native Method) 04-11
20:52:05.609: ERROR/AndroidRuntime(3675): at
java.lang.reflect.Method.invoke(Method.java:521) 04-11 20:52:05.609:
ERROR/AndroidRuntime(3675): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
04-11 20:52:05.609: ERROR/AndroidRuntime(3675): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 04-11
20:52:05.609: ERROR/AndroidRuntime(3675): at
dalvik.system.NativeStart.main(Native Method) 04-11 20:52:05.609:
ERROR/AndroidRuntime(3675): Caused by:
java.lang.IllegalStateException: Did you forget to call ‘public void
setup(LocalActivityManager activityGroup)’? 04-11 20:52:05.609:
ERROR/AndroidRuntime(3675): at
android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:654)
04-11 20:52:05.609: ERROR/AndroidRuntime(3675): at
android.widget.TabHost.setCurrentTab(TabHost.java:328) 04-11
20:52:05.609: ERROR/AndroidRuntime(3675): at
android.widget.TabHost.addTab(TabHost.java:213) 04-11 20:52:05.609:
ERROR/AndroidRuntime(3675): at
eu.pkg.tabsExample.TabsExampleActivity.initTabs(TabsExampleActivity.java:43)
04-11 20:52:05.609: ERROR/AndroidRuntime(3675): at
eu.pkg.tabsExample.TabsExampleActivity.onCreate(TabsExampleActivity.java:27)
04-11 20:52:05.609: ERROR/AndroidRuntime(3675): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-11 20:52:05.609: ERROR/AndroidRuntime(3675): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-11 20:52:05.609: ERROR/AndroidRuntime(3675): … 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-01T18:19:50+00:00Added an answer on June 1, 2026 at 6:19 pm

    Problem solved.
    The correct solution, as given by the user 207 in one of the comments, from another stackoverflow question is this:

    This is the XML:

    <?xml version="1.0" encoding="utf-8"?>
    
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TabHost android:id="@android:id/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="53px"
                    android:tabStripEnabled="false" android:layout_margin="1px"
                    android:background="#222222" />
                <FrameLayout android:id="@android:id/tabcontent"
                    android:layout_width="fill_parent" android:layout_height="fill_parent"
                    android:padding="5dp" />
            </LinearLayout>
        </TabHost>
    </LinearLayout>
    

    and java file:

    package eu.pkg.tabsExample;
    
    import android.app.Activity;
    import android.app.LocalActivityManager;
    import android.content.Intent;
    import android.content.res.Resources;
    import android.os.Bundle;
    import android.os.Handler;
    import android.widget.TabHost;
    
    public class TabsExampleActivity extends Activity {
    
        TabHost tabHost;
        LocalActivityManager mLocalActivityManager;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            initTabs(savedInstanceState);
        }
    
        @Override
        protected void onResume() {
            mLocalActivityManager.dispatchResume(); 
            super.onResume();
        }
    
        @Override
        protected void onPause() {
            mLocalActivityManager.dispatchPause(isFinishing());
            super.onPause();
        }
    
        private void initTabs(Bundle savedInstanceState) {
            Resources res = getResources();                     // Resource object to get Drawables
            tabHost = (TabHost) findViewById(android.R.id.tabhost);     // The activity TabHost
            mLocalActivityManager = new LocalActivityManager(this, false);
            mLocalActivityManager.dispatchCreate(savedInstanceState);
            tabHost.setup(mLocalActivityManager);
    
            TabHost.TabSpec spec;                               // Resusable TabSpec for each tab
            Intent intent;                                      // Reusable Intent for each tab        
    
            intent = new Intent("eu.pkg.tabsExample.BuildingTabActivity");
            spec = tabHost.newTabSpec("text").setIndicator("",
                              res.getDrawable(R.drawable.tab_text_selector))
                          .setContent(intent);
            tabHost.addTab(spec);
    
            intent = new Intent().setClass(this, ClipArtTabActivity.class);
            spec = tabHost.newTabSpec("clipart").setIndicator("",
                              res.getDrawable(R.drawable.tab_clipart_selector))
                          .setContent(intent);
            tabHost.addTab(spec);
    
    
            intent = new Intent().setClass(this, FrameSelectorTabActivity.class);
            spec = tabHost.newTabSpec("frame").setIndicator("",
                              res.getDrawable(R.drawable.tab_frame_selector))
                          .setContent(intent);
            tabHost.addTab(spec);
    
    
    
            intent = new Intent().setClass(this, BgSelectorTabActivity.class);
            spec = tabHost.newTabSpec("bg").setIndicator("",
                              res.getDrawable(R.drawable.tab_bg_selector))
                          .setContent(intent);
            tabHost.addTab(spec);
    
            intent = new Intent().setClass(this, BuildingTabActivity.class);
            spec = tabHost.newTabSpec("build").setIndicator("",
                              res.getDrawable(R.drawable.tab_build_selector))
                          .setContent(intent);
            tabHost.addTab(spec);
    
            tabHost.setCurrentTab(4);
        }
    }
    

    the magic behind the scene is in those 4 lines of code:

        tabHost = (TabHost) findViewById(android.R.id.tabhost);     // The activity TabHost
        mLocalActivityManager = new LocalActivityManager(this, false);
        mLocalActivityManager.dispatchCreate(savedInstanceState);
        tabHost.setup(mLocalActivityManager);
    

    Thank you all for contribution to this answer.

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

Sidebar

Related Questions

After repeated searching I have not found an elegant solution to this issue: how
Help please, After numerous hours searching for the solution to my problem i have
After searching quite a bit in the Internet for a solution I decided to
After searching online, the best solution I've found so far is to just make
After some searching, I got the following solution : reference . CLLocationCoordinate2D* new_coordinate =
After searching through some existing libraries for JSON, I have finally ended up with
After searching the other questions none have answered the specific issue I have. We
I have got a big problem. After searching through the internet, I didn't find
After searching many forums, I think my problem is how to type the question
This is related question to my previous question but different one. After searching a

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.