出现这个问题,有两个原因。
1.没有给TabHost中的FrameLayout标签加上id
解决:修改FrameLayout添加id属性
格式android:id=”@android:id/tabcontent ”
2.要检查最主要的几个标签。有没有写错的地方。比如单词拼错,等等。确实不要太相信xml解析器,坑很多。。。
类似的会出现的问题:
Your content must have a TabHost whose id attribute is ‘android.R.id.tabhost’
添加android:id=”@android:id/tabhost”, 这样就可以了
Your content must have a ListView whose id attribute is ‘android.R.id.list’
将ListView的id设置为“@android:id/list”或android:id=”@id/android:list”,这时可以用getListView来获取ListView的对象了
另外要注意:一个工程中只能有一个TabHost
//一个完整的例子
<?xml version=”1.0″ encoding=”utf-8″?>
<TabHost
android:id=”@android:id/tabhost”
xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”>
<LinearLayout
android:id=”@+id/LinearLayout01″
android:layout_height=”fill_parent”
android:layout_width=”fill_parent”
android:orientation=”vertical”>
<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_width=”fill_parent”
android:layout_height=”fill_parent”>
</FrameLayout>
</LinearLayout>
</TabHost>