Пытаюсь создать во втором активити динамически tabhost, но приложение сдало падать при запуске
Код: Выделить всё
TabHost tabHost = new TabHost(this);
tabHost.setup();
TabHost.TabSpec tabSpec;
tabSpec = tabHost.newTabSpec("tag1");
tabSpec.setIndicator("123 1");
tabSpec.setContent(R.id.title);
tabHost.addTab(tabSpec);
tabSpec = tabHost.newTabSpec("tag2");
tabSpec.setIndicator("123 2");
tabSpec.setContent(R.id.title);
tabHost.addTab(tabSpec);
tabSpec = tabHost.newTabSpec("tag3");
tabSpec.setIndicator("123 3");
tabSpec.setContent(R.id.title);
tabHost.addTab(tabSpec);
llgeneral.addView(tabHost);
Код: Выделить всё
06-27 12:28:40.540: E/AndroidRuntime(6761): FATAL EXCEPTION: main
06-27 12:28:40.540: E/AndroidRuntime(6761): Process: com.example.abc_harmful, PID: 6761
06-27 12:28:40.540: E/AndroidRuntime(6761): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.abc_harmful/com.example.abc_harmful.content_activity}: java.lang.RuntimeException: Your TabHost must have a TabWidget whose id attribute is 'android.R.id.tabs'
06-27 12:28:40.540: E/AndroidRuntime(6761): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
06-27 12:28:40.540: E/AndroidRuntime(6761): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
06-27 12:28:40.540: E/AndroidRuntime(6761): at android.app.ActivityThread.access$800(ActivityThread.java:135)
06-27 12:28:40.540: E/AndroidRuntime(6761): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
06-27 12:28:40.540: E/AndroidRuntime(6761): at android.os.Handler.dispatchMessage(Handler.java:102)
06-27 12:28:40.540: E/AndroidRuntime(6761): at android.os.Looper.loop(Looper.java:136)
06-27 12:28:40.540: E/AndroidRuntime(6761): at android.app.ActivityThread.main(ActivityThread.java:5001)
06-27 12:28:40.540: E/AndroidRuntime(6761): at java.lang.reflect.Method.invokeNative(Native Method)
06-27 12:28:40.540: E/AndroidRuntime(6761): at java.lang.reflect.Method.invoke(Method.java:515)
06-27 12:28:40.540: E/AndroidRuntime(6761): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
06-27 12:28:40.540: E/AndroidRuntime(6761): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
06-27 12:28:40.540: E/AndroidRuntime(6761): at dalvik.system.NativeStart.main(Native Method)
06-27 12:28:40.540: E/AndroidRuntime(6761): Caused by: java.lang.RuntimeException: Your TabHost must have a TabWidget whose id attribute is 'android.R.id.tabs'
06-27 12:28:40.540: E/AndroidRuntime(6761): at android.widget.TabHost.setup(TabHost.java:128)
06-27 12:28:40.540: E/AndroidRuntime(6761): at com.example.abc_harmful.content_activity.onCreate(content_activity.java:59)
06-27 12:28:40.540: E/AndroidRuntime(6761): at android.app.Activity.performCreate(Activity.java:5231)
06-27 12:28:40.540: E/AndroidRuntime(6761): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
06-27 12:28:40.540: E/AndroidRuntime(6761): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
06-27 12:28:40.540: E/AndroidRuntime(6761): ... 11 more
Это кусок XML
Код: Выделить всё
<TabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="@+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="@+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
С помощью дебага стало ясно, что вылетает на tabHost.setup(); , что может не нравится ему и причем тут TabWidget, в XML он присутствует.