删除选项卡并读取它会导致我的Android应用程序中出现以下错误

时间:2013-06-28 23:19:55

标签: android android-tabhost android-tabactivity

我为Android应用创建了一个tabbedActivity,当我删除其中一个标签并重新添加时,我收到以下错误

06-28 17:14:22.803: E/AndroidRuntime(18564): FATAL EXCEPTION: main
06-28 17:14:22.803: E/AndroidRuntime(18564): java.lang.IllegalArgumentException: you must specify a way to create the tab indicator.
06-28 17:14:22.803: E/AndroidRuntime(18564):    at android.widget.TabHost.addTab(TabHost.java:221)
06-28 17:14:22.803: E/AndroidRuntime(18564):    at com.eema.EvacRouteTableActivity$AsyncMap.onPostExecute(EvacRouteTableActivity.java:248)
06-28 17:14:22.803: E/AndroidRuntime(18564):    at com.eema.EvacRouteTableActivity$AsyncMap.onPostExecute(EvacRouteTableActivity.java:1)
06-28 17:14:22.803: E/AndroidRuntime(18564):    at android.os.AsyncTask.finish(AsyncTask.java:631)
06-28 17:14:22.803: E/AndroidRuntime(18564):    at android.os.AsyncTask.access$600(AsyncTask.java:177)
06-28 17:14:22.803: E/AndroidRuntime(18564):    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
06-28 17:14:22.803: E/AndroidRuntime(18564):    at android.os.Handler.dispatchMessage(Handler.java:99)
06-28 17:14:22.803: E/AndroidRuntime(18564):    at android.os.Looper.loop(Looper.java:137)
06-28 17:14:22.803: E/AndroidRuntime(18564):    at android.app.ActivityThread.main(ActivityThread.java:5041)
06-28 17:14:22.803: E/AndroidRuntime(18564):    at java.lang.reflect.Method.invokeNative(Native Method)
06-28 17:14:22.803: E/AndroidRuntime(18564):    at java.lang.reflect.Method.invoke(Method.java:511)
06-28 17:14:22.803: E/AndroidRuntime(18564):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-28 17:14:22.803: E/AndroidRuntime(18564):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-28 17:14:22.803: E/AndroidRuntime(18564):    at dalvik.system.NativeStart.main(Native Method)

这是我的代码:

        @Override
        protected void onPostExecute(Void unused) {

            dialog.dismiss();
            @SuppressWarnings("deprecation")
            TabActivity ta = (TabActivity) EvacRouteTableActivity.this.getParent();
            TabHost tabHost = ta.getTabHost();
            if (MapViewActivity.onCreateCalled >= 2){
                tabHost.getTabWidget().removeView(tabHost.getTabWidget().getChildTabViewAt(4));

                //Tab for the Map
                TabSpec mapSpec = tabHost.newTabSpec("Map");
                Intent mapIntent = new Intent(getBaseContext(), MapViewActivity.class);
                mapSpec.setContent(mapIntent); 
                tabHost.addTab(mapSpec);
                SystemClock.sleep(5000);
            }
            tabHost.setCurrentTab(4);
        }
    }

1 个答案:

答案 0 :(得分:1)

您应该设置标签指示

mapSpec.setIndicator("tab", res.getDrawable(R.drawable.icon));

mapSpec.setIndicator("tab");