views:

758

answers:

2

I am trying to create a tab widget with two tabs to open two different activities and written following layout to achieve this but it is giving me a NullPointerException.

Where is my mistake?

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    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"> 
        <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"> 
        </FrameLayout> 
    </LinearLayout> 
</TabHost>

In the Java class which is extending TabWidget I have the following code in the onCreate method:

setContentView(R.layout.more);

TabHost mTabHost = (TabHost) this.findViewById(R.id.tabhost);
mTabHost.setup();

Intent intent;

intent = new Intent().setClass(this, Settings.class);
mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator(
                        "Calculator", 
                        getResources().getDrawable(R.drawable.tab01)).setContent(intent));

intent = new Intent().setClass(this, Post.class);                
mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator(
                        "YouTube", 
                        getResources().getDrawable(R.drawable.tab02)).setContent(intent));
A: 

not much info to go on here, but check my question (and it's answers) for a potential solution
http://stackoverflow.com/questions/2209406/issues-with-android-tabhost-example

KevinDTimm
i have already corrected these problems.. but the problem is in my layout file.. i have just copied the code of layout mentioned in the android tabactivity example ...still no hope..
UMMA
A: 

if you are extending your tab class using TabActivity then it is must

to use ids of tab related controls like "@android:id/tabhost"

i was using "@+id/tabhost" which is wrong but in case of extending it through Activity class its fine.

and above problem which i was facing on layout will not come...

Tab tutorial was also bit buggy it can be solved using following example. Example

UMMA
So, have you fixed it or not?
KevinDTimm
yes fixed now..
UMMA