Your content must have a TabHost whose id attribute is 'android.R.id.tabhost' 解决
2013-04-24 15:18
381 查看
问题1. 运行Activity的时候出现Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'
添加Layout的时候,xml跟元素选择TabHost, 但是ADT没有添加id属性, 运行的时候,会提示Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'错误, 需要添加android:id="@android:id/tabhost", 这样就可以了。
问题2. 运行Activity的时候出现Your TabHost must have a TabWidget whose id attribute is 'android.R.id.tabcontent'
解决方法: 修改FrameLayout添加id属性, ADT自动生成的xml文件中Id是android:id="@+id/FrameLayout01 ", 需要修改成下面的格式android:id="@android:id/tabcontent ",这个估计会困扰一大批初学者,谁会想到会修改这个地方,看到错误很容易修改成tabcontent,但是前缀不容易想到。 而且在ADT可视化编辑这个文件的时候, 界面上显示NullPointerException,这个是ADT的一个BUG。
xml文件代码:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<!-- 实现Tab标签的居底主要是通过设置属性 android:layout_weight="1" -->
<!-- 还要注意FrameLayout标签的位置,要写在TabWidget标签的前面 -->
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</LinearLayout>
</TabHost>
添加Layout的时候,xml跟元素选择TabHost, 但是ADT没有添加id属性, 运行的时候,会提示Your content must have a TabHost whose id attribute is 'android.R.id.tabhost'错误, 需要添加android:id="@android:id/tabhost", 这样就可以了。
问题2. 运行Activity的时候出现Your TabHost must have a TabWidget whose id attribute is 'android.R.id.tabcontent'
解决方法: 修改FrameLayout添加id属性, ADT自动生成的xml文件中Id是android:id="@+id/FrameLayout01 ", 需要修改成下面的格式android:id="@android:id/tabcontent ",这个估计会困扰一大批初学者,谁会想到会修改这个地方,看到错误很容易修改成tabcontent,但是前缀不容易想到。 而且在ADT可视化编辑这个文件的时候, 界面上显示NullPointerException,这个是ADT的一个BUG。
xml文件代码:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<!-- 实现Tab标签的居底主要是通过设置属性 android:layout_weight="1" -->
<!-- 还要注意FrameLayout标签的位置,要写在TabWidget标签的前面 -->
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</LinearLayout>
</TabHost>
相关文章推荐
- Your content must have a TabHost whose id attribute is 'android.R.id.tabhost' 解决
- Your content must have a TabHost whose id attribute is 'android.R.id.tabhost' 解决
- Android: Your content must have a TabHost whose id attribute is ‘android.R.id.tabhost’ 错误分析及解决方法
- Your content must have a TabHost whose id attribute is 'android.R.id.tabhost' 问题,写了id语句仍出错的解决办法
- Your content must have a TabHost whose id attribute is 'android.R.id.tabhost' 解决
- Your content must have a TabHost whose id attribute is 'android.R.id.tabhost' 解决
- Your content must have a TabHost whose id attribute is 'android.R.id.tabhost' 解决
- java.lang.RuntimeException: Your content must havea TabHost whose id attribute is‘android.R.id.tabhost’
- Android Your content must have a ListView whose id attribute is 'android.R.id.list'错误的解决办法
- Android中 Your content must have a ListView whose id attribute is 'android.R.id.list'错误的解决办法
- Android Your content must have a ListView whose id attribute is 'android.R.id.list'错误的解决办法
- 5 Your TabHost must have a TabWidget whose id attribute is ‘android.R.id.tabcontent’
- [ERROR]Your TabHost must have a TabWidget whose id attribute is 'android.R.id.tabcontent'
- Android中 Your content must have a ListView whose id attribute is 'android.R.id.list'错误的解决办法
- Your content must have a ListView whose id attribute is 'android.R.id.list' 解决方法
- 解决Your content must have a ListView whose id attribute is 'android.R.id.list'
- 解决Your content must have a ListView whose id attribute is ‘android.R.id.list
- Android—Android中 Your content must have a ListView whose id attribute is 'android.R.id.list'错误的解决办法
- Your content must have a ListView whose id attribute is 'android.R.id.list'解决办法
- [BUG]Your TabHost must have a TabWidget whose id attribute is ‘android.R.id.tabcontent’