In my android app I have few Tabs .The app runs fine , but whenever I press home on the second tab of any Tabhost and restart it back by pressing home (recent items ) it crashes and a nullpointer at :
04-28 15:47:06.177: W/System.err(25731): java.lang.NullPointerException
04-28 15:47:06.207: W/System.err(25731): at android.widget.TabWidget.setCurrentTab(TabWidget.java:339)
04-28 15:47:06.207: W/System.err(25731): at android.widget.TabWidget.focusCurrentTab(TabWidget.java:363)
04-28 15:47:06.207: W/System.err(25731): at android.widget.TabHost.setCurrentTab(TabHost.java:320)
04-28 15:47:06.207: W/System.err(25731): at android.widget.TabHost.addTab(TabHost.java:213)
04-28 15:47:06.207: W/System.err(25731): at com.cuelearn.main.ChapterTab.onResume(ChapterTab.java:82)
04-28 15:47:06.207: W/System.err(25731): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1149)
04-28 15:47:06.237: W/System.err(25731): at android.app.Activity.performResume(Activity.java:3823)
And then:
04-28 15:47:06.177: W/System.err(25731): java.lang.NullPointerException
04-28 15:47:06.207: W/System.err(25731): at android.widget.TabWidget.setCurrentTab(TabWidget.java:339)
04-28 15:47:06.207: W/System.err(25731): at android.widget.TabWidget.focusCurrentTab(TabWidget.java:363)
04-28 15:47:06.207: W/System.err(25731): at android.widget.TabHost.setCurrentTab(TabHost.java:320)
04-28 15:47:06.207: W/System.err(25731): at android.widget.TabHost.addTab(TabHost.java:213)
04-28 15:47:06.207: W/System.err(25731): at com.cuelearn.main.ChapterTab.onResume(ChapterTab.java:82)
04-28 15:47:06.207: W/System.err(25731): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1149)
04-28 15:47:06.237: W/System.err(25731): at android.app.Activity.performResume(Activity.java:3823)
04-28 15:47:06.827: E/AndroidRuntime(25731): FATAL EXCEPTION: main
04-28 15:47:06.827: E/AndroidRuntime(25731): java.lang.NullPointerException
04-28 15:47:06.827: E/AndroidRuntime(25731): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
04-28 15:47:06.827: E/AndroidRuntime(25731): at android.widget.TabWidget.dispatchDraw(TabWidget.java:271)
04-28 15:47:06.827: E/AndroidRuntime(25731): at android.view.View.draw(View.java:6743)
04-28 15:47:06.827: E/AndroidRuntime(25731): at android.view.ViewGroup.drawChild(ViewGroup.java:1640)
I am a newbie to this Please help me?I have to do this last task to complete my app so Please help?
EDIT
@Override
public void onResume()
{
super.onResume();
// addTabs();
tabHost=getTabHost();
tabHost.clearAllTabs();
try{
tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("All").setContent(new Intent(this, ChTable.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
tabHost.addTab(tabHost.newTabSpec("tab4").setIndicator("New").setContent(
new Intent(this, ChapterNew.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
tabHost.setCurrentTab(tabbed);
tabHost.getTabWidget().getChildAt(0).getLayoutParams().height =35;
tabHost.getTabWidget().getChildAt(1).getLayoutParams().height =35;
}
catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}
}
tabHost.setCurrentTab(tabbed);
It looks like your ‘tabbed’ is not defined or valid.