Skip to content Skip to sidebar Skip to footer

Nullpointer Exception In Setting Up A Tabhost At Calling Addtab( Tabhost.tabspec Spec) Method

this question is really wierd and driving me crazy. i can't get rid of the nullPointerException. my task is quite simple, just run a test on the tabhost. but now i'm not able to ev

Solution 1:

//change your tabhost id to

<TabHost 
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

//your activity which extends TabActivity like this below one

publicclassHelloTabWidgetextendsTabActivity {

//in your onCreate do this

TabHosttabHost= getTabHost();  // The activity TabHost
    TabHost.TabSpec spec;  // Resusable TabSpec for each tab
    Intent intent;  // Reusable Intent for each tab

check this:

Solution 2:

you need to extend TabActivity not simple activity try

publicclassCaoextendsTabActivity

intead of

publicclassCaoextendsActivity

and change this

menu_host = (TabHost) findViewById(R.id.tabhost);

to menu_host =getTabHost(); and

 android:id="@+id/tabhost"

to

android:id="@android:id/tabhost"

Solution 3:

All that was needed for me was to change the way I declared the ID of the TabHost in .xml. Rather than using "@+id/tabhost", I used "@android:id/tabhost". Then, when assigning my TabHost in code, I called findViewById(android.R.id.tabhost). This, for whatever reason, fixed my problem.

Post a Comment for "Nullpointer Exception In Setting Up A Tabhost At Calling Addtab( Tabhost.tabspec Spec) Method"