问题提出

错误提示: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’的问题:

很可能是因为我们要实现对ListView中setOnItemClick的事件监听而去继承了LiseActivity,但是却没有ListView的标签,解决问题方法很简单:

ListView的id设置为“@android:id/list”或android:id=”@id/android:list”

用getListView来获取ListView的对象了。

    <ListView
android:id="@android:id/list" 或android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</ListView>

lsitActivity的使用说明

待补充

ListActivity ListView的id为什么要用@android:id/list

关于id的知识

@+id/android:list"和"@android:id/list"的写法

2.同样容易报此错误的还有TabHost,如下:

问题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
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>

注意: 如果用TabHost的话, 上面标红的三处必须是一样, 这个是Google的约定。 而且一个工程中只能有一个TabHost。

来源:http://blog.csdn.net/yg6111/article/details/6908251

http://blog.sina.com.cn/s/blog_94103cd90100zokn.html

相关链接 >

Android中 Your content must have a ListView whose id attribute is 'android.R.id.list'错误的解决办法

使用ListView 时,遇到了 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和ListView注意

初学时遇到的小问题Your content must have a ListView whose id attribute is 'android.R.id.list'的更多相关文章

  1. Andriod学习笔记2:“Your content must have a ListView whose id attribute is 'android.R.id.list'”问题的解决办法

    问题描述 activity_main.xml代码如下: <?xml version="1.0" encoding="utf-8"?> <Lin ...

  2. Android Your content must have a ListView whose id attribute is 'android.R.id.list'错误的解决办法

    在Android开发中,ListView有着很重要的地位,使用的场合也非常的多 错误提示:Your content must have a ListView whose id attribute is ...

  3. 使用ListView 时,遇到了 Your content must have a ListView whose id attribute is 'android.R.id.list' 错误

    今天在开发Android小应用的时候,使用到了ListView,在使用自己创建的listview风格的时候,就出现了如标题的错误提示信息,这个就让我纳闷了,以前也不会出现这个问题啊,而且也可以运行,赶 ...

  4. Your content must have a ListView whose id attribute is 'android.R.id.list'

    修改ListView的ID为 ' @android:id/list ' <ListView android:id="@android:id/list" android:lay ...

  5. 三行代码接入,社交软件打字时底下弹出的表情布局,自定义ViewPager+页面点标+各种功能的android小框架。

    (转载请声明出处:http://www.cnblogs.com/linguanh/) 前言: 接上次分享的 ListView 动态加载类,入口:http://www.cnblogs.com/lingu ...

  6. 初学划分树,小见解之!POJ-2104/HDU-2665

    划分树 本来是学主席树的,可怜我等巨弱观群巨博客难解fotle主席的思想精髓.于是学了一下划分树,嗯,花了一下午时间理解build(其实自己模拟一遍就通了),我很难理解为什么划分树会看不懂而能学会主席 ...

  7. 移除HTML5 input在type="number"时的上下小箭头

    /*移除HTML5 input在type="number"时的上下小箭头*/ input::-webkit-outer-spin-button, input::-webkit-in ...

  8. gdb调试运行时的程序小技巧

    使用gdb调试运行时的程序小技巧 标签: 未分类 gdb pstack | 发表时间:2012-10-15 04:32 | 作者:士豪 分享到: 出处:http://rdc.taobao.com/bl ...

  9. 关于eclipse的indigo版中文注释时字体太小的问题(转)

    eclipse目前最新版代号indigo, 在win7上使用时中文注释时字体太小的问题. 为什么会这样? 首先我们应该知道, 在win7系统中, font是有"显示"和" ...

随机推荐

  1. Python线程的常见的lock

    IO阻塞分析: 下面该需求很简单将一个数值100做自减处到0.主函数中有0.1秒的IO阻塞 import threading import time def sub(): global num # 掌 ...

  2. C# App 中嵌入 Chrome 浏览器

    http://www.codeceo.com/article/cefsharp-charp-app-chrome.html http://developer.51cto.com/art/201304/ ...

  3. LINUX 笔记-Shell 脚本控制语句

    1.if 语句 if condition1;then command1 elif condition2;then command2 else command3 fi 2.case 语句 case va ...

  4. 自学Java HashMap源码

    自学Java HashMap源码 参考:http://zhangshixi.iteye.com/blog/672697 HashMap概述 HashMap是基于哈希表的Map接口的非同步实现.此实现提 ...

  5. IsoAlgo3d - A PCF 3D Viewer for Desktop, Tablet and Smart phone

    IsoAlgo3d - A PCF 3D Viewer for Desktop, Tablet and Smart phone eryar@163.com Abstract. IsoAlgo3d 通过 ...

  6. Leetcode题解(四)

    12/13.Integer to Roman/Roman to Integer 题目 罗马数字规则: 符号 I V X L C D M 数字 1 5 10 50 100 500 1000 代码如下: ...

  7. Connect the Cities(prim)用prim都可能超时,交了20几发卡时过的

    Connect the Cities Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...

  8. Nginx详解以及LNMP的搭建

    v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VM ...

  9. indexed database IndexedDB

    Indexed Database API 目的是提供一个可供javascript存储和检索对象,并且还能进行查询,搜索等数据库操作   设计为几乎完全异步,因此绝大部分操作都稍后执行,因此每次操作都应 ...

  10. vue.js项目安装

    Vue.js 安装 NPM 方法安装vue.js项目 npm 版本需要大于 3.0,如果低于此版本需要升级它: # 查看版本 $ npm -v 2.3.0 #升级 npm npm install np ...