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));