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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:36:51+00:00 2026-05-22T22:36:51+00:00

I am following the directions for a TabLayout . Everything is pretty much an

  • 0

I am following the directions for a TabLayout. Everything is pretty much an exact copy from that page.

public class DashboardActivity extends TabActivity {

the problem is that in this line TabHost tabHost = getTabHost();, tabHost is always null, which causes a null pointer exception in the TabActivity base class.

Is there something I am missing?

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    profile = Controller.getProfile();

    this.setContentView(R.layout.test);

    buildTabs();
}

private void buildTabs()
{
    Resources res = getResources(); // Resource object to get Drawables
    TabHost tabHost = getTabHost();// The activity TabHost

    if(tabHost != null)
    {
        // Initialize a TabSpec for each tab and add it to the TabHost
        TabSpec statementSpec = tabHost.newTabSpec("statements").setIndicator("Statements (" + profile.Statements.length + ")",
                          res.getDrawable(R.drawable.ic_tabs_statements))
                      .setContent(new Intent().setClass(DashboardActivity.this, SplashActivity.class));
        tabHost.addTab(statementSpec);

        TabSpec paymentSpec = tabHost.newTabSpec("payments").setIndicator("Payments (" + profile.Items.length + ")",
                          res.getDrawable(R.drawable.ic_tabs_payments))
                      .setContent(new Intent().setClass(DashboardActivity.this, SplashActivity.class));
        tabHost.addTab(paymentSpec);

        tabHost.setCurrentTab(0);
    }
}

Layout

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    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="wrap_content" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp" />
    </LinearLayout>
</TabHost>

state-list drawable

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- When selected, use grey -->
    <item android:drawable="@drawable/ic_tab_active"
          android:state_selected="true" />
    <!-- When not selected, use white-->
    <item android:drawable="@drawable/ic_tab_suspended" />
</selector>

I even tried moving the images in the state-list drawable from /rex/drawable to /res/drawable-hdpi. I always get the same error.

05-31 21:22:23.753: ERROR/AndroidRuntime(647): FATAL EXCEPTION: main
05-31 21:22:23.753: ERROR/AndroidRuntime(647): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ftni.consumer/com.ftni.consumer.ui.DashboardActivity}: java.lang.NullPointerException
05-31 21:22:23.753: ERROR/AndroidRuntime(647):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
05-31 21:22:23.753: ERROR/AndroidRuntime(647):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
05-31 21:22:23.753: ERROR/AndroidRuntime(647):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-31 21:22:23.753: ERROR/AndroidRuntime(647):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
05-31 21:22:23.753: ERROR/AndroidRuntime(647):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-31 21:22:23.753: ERROR/AndroidRuntime(647):     at android.os.Looper.loop(Looper.java:123)
05-31 21:22:23.753: ERROR/AndroidRuntime(647):     at android.app.ActivityThread.main(ActivityThread.java:3647)
05-31 21:22:23.753: ERROR/AndroidRuntime(647):     at java.lang.reflect.Method.invokeNative(Native Method)
05-31 21:22:23.753: ERROR/AndroidRuntime(647):     at java.lang.reflect.Method.invoke(Method.java:507)
05-31 21:22:23.753: ERROR/AndroidRuntime(647):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-31 21:22:23.753: ERROR/AndroidRuntime(647):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-31 21:22:23.753: ERROR/AndroidRuntime(647):     at dalvik.system.NativeStart.main(Native Method)
05-31 21:22:23.753: ERROR/AndroidRuntime(647): Caused by: java.lang.NullPointerException
05-31 21:22:23.753: ERROR/AndroidRuntime(647):     at android.app.TabActivity.onPostCreate(TabActivity.java:79)
05-31 21:22:23.753: ERROR/AndroidRuntime(647):     at android.app.Instrumentation.callActivityOnPostCreate(Instrumentation.java:1108)
05-31 21:22:23.753: ERROR/AndroidRuntime(647):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1605)

Has anyone else had problems implementing the standard tab activity? Any pointers on what I am doing wrong?

  • 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-22T22:36:52+00:00Added an answer on May 22, 2026 at 10:36 pm

    Try putting all of the code for buildTabs() in your onCreate() method.

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

Sidebar

Related Questions

I've been following the developer.android.com page http://developer.android.com/guide/publishing/licensing.html#lc-lcc for directions on using the ServerManagedPolicy type
Please see the following code to understand my question better. class compareByValue { public:
Here are the directions: Implement the following method so that it prints all even-valued
Following the directions from many articles, I've decided to implement the Unit of work
I'm trying to run the following line: Directions.loadFromWaypoints((Waypoint[])waypoints.toArray(), opts); But I'm getting: 23:41:44.595 [ERROR]
I'm building a custom print template closely following the directions in Chuck Ainslie's articles
Following is the association between 2 models: class FotoGossip < ActiveRecord::Base has_many :uploads end
I was following the directions at http://django-dajaxice.readthedocs.org/en/latest/installation.html to install Dajaxice for simple AJAX support
How can i show the following result: http://maps.googleapis.com/maps/api/directions/json?origin=hadera&destination=haifa&sensor=false on a map? i want to
i am following a tutorial on a simple cocos2d game . however on 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.