2

我一直在尝试将三个不同的活动分别添加到不同的选项卡中......一个活动是开始蓝牙发现和选择蓝牙设备以进行配对

第二个将是基于蓝牙的鼠标垫

我在关注很多网上的东西..基本上这个http://www.androidhive.info/2011/08/android-tab-layout-tutorial/

但不知何故,它显示了这个错误

11-08 13:41:24.673: D/AndroidRuntime(22886): Shutting down VM
11-08 13:41:24.673: W/dalvikvm(22886): threadid=1: thread exiting with uncaught exception (group=0x40ab6228)
11-08 13:41:24.714: E/AndroidRuntime(22886): FATAL EXCEPTION: main
11-08 13:41:24.714: E/AndroidRuntime(22886): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.kant.BluetoothTest2/com.kant.BluetoothTest2.TabControllerActivity}: java.lang.RuntimeException: Your TabHost must have a FrameLayout whose id attribute is 'android.R.id.tabcontent'
11-08 13:41:24.714: E/AndroidRuntime(22886):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2194)
11-08 13:41:24.714: E/AndroidRuntime(22886):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2229)
11-08 13:41:24.714: E/AndroidRuntime(22886):    at android.app.ActivityThread.access$600(ActivityThread.java:139)
11-08 13:41:24.714: E/AndroidRuntime(22886):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1261)
11-08 13:41:24.714: E/AndroidRuntime(22886):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-08 13:41:24.714: E/AndroidRuntime(22886):    at android.os.Looper.loop(Looper.java:154)
11-08 13:41:24.714: E/AndroidRuntime(22886):    at android.app.ActivityThread.main(ActivityThread.java:4945)
11-08 13:41:24.714: E/AndroidRuntime(22886):    at java.lang.reflect.Method.invokeNative(Native Method)
11-08 13:41:24.714: E/AndroidRuntime(22886):    at java.lang.reflect.Method.invoke(Method.java:511)
11-08 13:41:24.714: E/AndroidRuntime(22886):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-08 13:41:24.714: E/AndroidRuntime(22886):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-08 13:41:24.714: E/AndroidRuntime(22886):    at dalvik.system.NativeStart.main(Native Method)
11-08 13:41:24.714: E/AndroidRuntime(22886): Caused by: java.lang.RuntimeException: Your TabHost must have a FrameLayout whose id attribute is 'android.R.id.tabcontent'
11-08 13:41:24.714: E/AndroidRuntime(22886):    at android.widget.TabHost.setup(TabHost.java:163)
11-08 13:41:24.714: E/AndroidRuntime(22886):    at android.widget.TabHost.setup(TabHost.java:182)
11-08 13:41:24.714: E/AndroidRuntime(22886):    at android.app.TabActivity.onContentChanged(TabActivity.java:135)
11-08 13:41:24.714: E/AndroidRuntime(22886):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:281)
11-08 13:41:24.714: E/AndroidRuntime(22886):    at android.app.Activity.setContentView(Activity.java:1885)
11-08 13:41:24.714: E/AndroidRuntime(22886):    at com.kant.BluetoothTest2.TabControllerActivity.onCreate(TabControllerActivity.java:16)
11-08 13:41:24.714: E/AndroidRuntime(22886):    at android.app.Activity.performCreate(Activity.java:4531)
11-08 13:41:24.714: E/AndroidRuntime(22886):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071)
11-08 13:41:24.714: E/AndroidRuntime(22886):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2150)
11-08 13:41:24.714: E/AndroidRuntime(22886):    ... 11 more

帮助将不胜感激

4

1 回答 1

1

正如这里所说:

11-08 13:41:24.714: E/AndroidRuntime(22886): Caused by: java.lang.RuntimeException: 你的 TabHost 必须有一个 id 属性为 'android.R.id.tabcontent' 的 FrameLayout

您缺少具有正确 ID 的 frameLayout,因此请查看我的代码并尝试执行相同操作。希望能帮助到你 :)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rootview"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<TabHost
    android:id="@+id/mainTabHost"
    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" >

                 <include layout="@layout/view_offer_tab1" />
                 <include layout="@layout/view_offer_tab2" />


        </FrameLayout>
    </LinearLayout>
</TabHost>

于 2012-11-08T08:33:24.923 回答