0

自从我因错误重新启动 adb 后,我就遇到过某种活动崩溃,以前运行良好。现在,当我单击该活动时,我得到了这个崩溃:

java.lang.RuntimeException:无法启动活动 ComponentInfo{com.example.minecraftultimate/com.example.minecraftultimate.SeedsActivity}:java.lang.RuntimeException:您的内容必须有一个 id 属性为“android.R.id”的 TabHost。标签主机'

但问题是,该活动确实有一个标签主机,其 id 为标签主机。这是我的 XML 和活动类:

活动种子.xml:

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
      android:id="@android:id/tabhost">

    <LinearLayout
            android:id="@+id/LinearLayout01"
            android:orientation="vertical"
            android:layout_height="fill_parent"
            android:layout_width="fill_parent">

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_height="wrap_content"
                android:layout_width="fill_parent">
            </TabWidget>

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_height="fill_parent"
                 android:layout_width="fill_parent">
            </FrameLayout>

    </LinearLayout>

</TabHost>

这是我的SeedsActivity.class

package com.example.minecraftultimate;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TabWidget;

@SuppressWarnings("deprecation")
public class SeedsActivity extends TabActivity {

@Override
public void onCreate(Bundle savedInstanceState)
{
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_seeds);

        // create the TabHost that will contain the Tabs
        TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);


        TabSpec tab1 = tabHost.newTabSpec("Vanilla");
        TabSpec tab2 = tabHost.newTabSpec("Biomes O' Plenty");
        TabSpec tab3 = tabHost.newTabSpec("Extra Biomes XL");

       // Set the Tab name and Activity
       // that will be opened when particular Tab will be selected
        tab1.setIndicator("Vanilla");
        tab1.setContent(new Intent(this,VanillaSeedsActivity.class));

        tab2.setIndicator("Biomes O'P.");
        tab2.setContent(new Intent(this,BOPSeedsActivity.class));

        tab3.setIndicator("Extra Biomes XL");
        tab3.setContent(new Intent(this,ExtraBSeedsActivity.class));

        /** Add the tabs  to the TabHost to display. */
        tabHost.addTab(tab1);
        tabHost.addTab(tab2);
        tabHost.addTab(tab3);

 }

}
4

1 回答 1

0

您可以使用

TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);

或者

TabHost tabHost = getTabHost();

只需清理您的项目一次,然后运行它可能会解决您的问题。

于 2014-01-10T06:33:31.590 回答