尝试通过按主页按钮重新启动我的应用程序时出错?

时间:2012-04-28 10:21:04

标签: android android-tabhost

在我的Android应用程序中,我有几个标签。该应用程序运行良好,但每当我在任何Tabhost的第二个选项卡上按回家并通过按回家(最近的项目)重新启动它它崩溃和nullpointer在:

   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)

我是这个的新手请帮助我?我必须完成最后一项任务才能完成我的应用所以请帮忙吗?

修改

@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
    }

}

1 个答案:

答案 0 :(得分:0)

tabHost.setCurrentTab(标签); 看起来您的“标签”未定义或有效。