0
在我的Android應用我有幾個標籤.The應用程序運行正常,但每當我按任意Tabhost的第二個選項卡上的家,回到按家庭(最近的項目)重新啓動它崩潰和一個空指針在:嘗試按Home按鈕重啓我的應用程序時出錯?
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.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)
我是一個新手,這個請幫助我,我必須這樣做,最後的任務完成我的應用程序,所以請幫助?
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
}
}
你有沒有使用過任何靜態參考? – 2012-04-28 10:24:44
我不知道我是noob。我如何使用一個.will在這裏幫助? – Navdroid 2012-04-28 10:26:02
請稍等一些代碼! – 2012-04-28 10:26:42