错误处理:your content must have a TabHost whose id attribute is 'android.R.id.tabhost'

来源:互联网 发布:sql server 聚合 编辑:程序博客网 时间:2024/05/17 08:09

activity_main.xml如下

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:background="#EEEEEE"    android:orientation="vertical" >    <LinearLayout        android:id="@+id/linearLayout1"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:background="#EEEEEE"        >        <TextView            android:id="@+id/text1"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_weight="1.0"            android:gravity="center"            android:text="标题1"            android:textColor="#000000"            android:textSize="18.0dip" />        <TextView            android:id="@+id/text2"            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:layout_weight="1.0"            android:gravity="center"            android:text="标题2"            android:textColor="#000000"            android:textSize="18.0dip" />        <TextView            android:id="@+id/text3"            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:layout_weight="1.0"            android:gravity="center"            android:text="标题3"            android:textColor="#000000"            android:textSize="18.0dip" />    </LinearLayout>    <ImageView        android:id="@+id/cursor"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:background="#EEEEEE"        android:scaleType="matrix"        android:src="@drawable/offine" /></LinearLayout>


MainActivity.java如下:

public class MainActivity extends TabActivity {@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}}

调试时,始终报如下错误:

04-30 09:38:17.309: E/AndroidRuntime(17324): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gocom.traincheck/com.gocom.traincheck.activity.MainActivity}: java.lang.RuntimeException: Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'

经多次尝试,问题找到,原因是MainActivity.java继承了TabActivity,因此在activity_main.xml中必须有类似以下的定义:

<TabHost         android:id="@android:id/tabhost"

.....



1 1
原创粉丝点击