Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android标签问题引发运行时问题(但对我来说很好)_Android_Xml_Runtime_Android Tabhost - Fatal编程技术网

Android标签问题引发运行时问题(但对我来说很好)

Android标签问题引发运行时问题(但对我来说很好),android,xml,runtime,android-tabhost,Android,Xml,Runtime,Android Tabhost,Tabhost抛出运行时错误-代码对我来说似乎很好-但显然不是。我有两个活动要在一些选项卡中显示 错误 (java.lang.IllegalArgumentException:必须指定创建选项卡内容的方法) main活动 public class MainActivity extends TabActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.o

Tabhost抛出运行时错误-代码对我来说似乎很好-但显然不是。我有两个活动要在一些选项卡中显示

错误

(java.lang.IllegalArgumentException:必须指定创建选项卡内容的方法)

main活动

public class MainActivity extends TabActivity
{

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        TabHost tabHost = getTabHost();


        // Tab 1
        TabHost.TabSpec tab1 = tabHost.newTabSpec("tab1");
        // setting Title and Icon for the Tab

        tab1.setIndicator("", getApplicationContext().getResources().getDrawable(R.drawable.drawtab1));
        Intent tab1Intent = new Intent(this, Tab1Activity.class);
        tab1Intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        tab1.setContent(tab1Intent);


        // Tab 2
        TabHost.TabSpec tab2 = tabHost.newTabSpec("tab2");
        // setting Title and Icon for the Tab

        tab2.setIndicator("", getApplicationContext().getResources().getDrawable(R.drawable.drawtab1));
        Intent tab2Intent = new Intent(this, Tab2Activity.class);
        tab1Intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        tab1.setContent(tab2Intent);


        tabHost.addTab(tab1);
        tabHost.addTab(tab2);


    }
}
XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:tools="http://schemas.android.com/tools"
              android:id="@+id/LinearLayout1"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical"
              android:paddingBottom="@dimen/activity_vertical_margin"
              android:paddingLeft="@dimen/activity_horizontal_margin"
              android:paddingRight="@dimen/activity_horizontal_margin"
              android:paddingTop="@dimen/activity_vertical_margin"
              tools:context="com.example.dawnlp.innertab.MainActivity"
              android:background="#00547d"
              android:textColor="#FFFFFF"

    >



    <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"

                >


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

</LinearLayout>


不要认为这与我的其他活动有关。

将最后一个选项卡代码更改为: 对于指示器,您使用的是tab1而不是tab2

 // Tab 2
        TabHost.TabSpec tab2 = tabHost.newTabSpec("tab2");
        // setting Title and Icon for the Tab

        tab2.setIndicator("", getApplicationContext().getResources().getDrawable(R.drawable.drawtab1));
        Intent tab2Intent = new Intent(this, Tab2Activity.class);
        tab2Intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        tab2.setContent(tab2Intent);