I have created a TabActivity and added TabWidget and frame to the layout.
I have four other Activity classes with single label in each Activity. Four tabs are associated with four tabs.
When I am trying to launch the application in emulator, I am getting the below exception
09-03 23:24:43.905: ERROR/AndroidRuntime(450):
java.lang.NullPointerException 09-03 23:24:43.905:
ERROR/AndroidRuntime(450): at
android.widget.TabHost.dispatchWindowFocusChanged(TabHost.java:295)
09-03 23:24:43.905: ERROR/AndroidRuntime(450): at
android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661)
09-03 23:24:43.905: ERROR/AndroidRuntime(450): at
android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:661)
public class TabHome extends TabActivity {
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost=getTabHost();
TabHost.TabSpec tabSpec;
Resources res=getResources();
Intent intent;
intent=new Intent().setClass(this, MyMap.class);
tabSpec= tabHost.newTabSpec("Maps").setIndicator("Maps",res.getDrawable(R.drawable.ic_tab_artists)).setContent(intent);
tabHost.addTab(tabSpec);
intent=new Intent().setClass(this, MyStash.class);
tabSpec= tabHost.newTabSpec("Stash").setIndicator("Stash",res.getDrawable(R.drawable.ic_tab_artists)).setContent(intent);
tabHost.addTab(tabSpec);
intent=new Intent().setClass(this, MyList.class);
tabSpec= tabHost.newTabSpec("List").setIndicator("List",res.getDrawable(R.drawable.ic_tab_artists)).setContent(intent);
tabHost.addTab(tabSpec);
intent=new Intent().setClass(this, MySearch.class);
tabSpec= tabHost.newTabSpec("Search").setIndicator("Search",res.getDrawable(R.drawable.ic_tab_artists)).setContent(intent);
tabHost.addTab(tabSpec);
tabHost.setCurrentTab(2);
}
I have missed to mention the following attributes to main.xml
android:id=”@android:id/tabhost” in TabHost tag
and
android:id=”@android:id/tabs” in TabWidget tag
and
android:id=”@android:id/tabcontent” in FrameLayout tag.
Thanks all for your help!