Android-使用tabActivity时始终强制关闭

Android-使用tabActivity时始终强制关闭,android,Android,我有一个关于android tabactivity的问题。 我只使用了一个.java和两个.xml文件来尝试开发一个简单的选项卡视图,但失败了:( 这是我的Main.java public class Main extends TabActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) {

我有一个关于android tabactivity的问题。 我只使用了一个.java和两个.xml文件来尝试开发一个简单的选项卡视图,但失败了:(

这是我的Main.java

public class Main extends TabActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        TabHost tabHost = getTabHost();
       tabHost.addTab(tabHost.newTabSpec("page1").setIndicator("Page1").setContent(R.id.view1));
        tabHost.setCurrentTab(0);
    }
}
这是main.xml

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="5dp">
        <TabWidget
            android:id="@+id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:id="@+id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp" />
    </LinearLayout>
</TabHost>

这是abc.xml(包括view1)


你能帮我复习一下密码吗(
非常感谢。

您的id/view1 LinearLayout必须是id/tabcontent FrameLayout的子项。

您有
logcat
输出吗?请显示您的logcat输出。它应该会告诉我们错误及其发生在代码中的位置。同时提供
getTabHost()的代码
。你发布的所有内容看起来都不错,所以我猜答案在view1.xml中……你能发布吗?我刚刚意识到
getTabHost()
TabActivity
的一种方法。很抱歉。我只是猜测一下-abc.xml中的
线性布局是否也应该包括
android:orientation=“vertical”
attr?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:id="@+id/view1">
<TextView android:text="ABC"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>