前几天在使用Android的ListActivity过程中,发现不论怎么写,都会报错Your content must have a ListView whose id attribute is ‘android.R.id.list’

收到如下错误提示时错误定位在setContentView这一行

猜想可能是setContentView的资源文件里没找到一个id为list的ListView控件

<?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:orientation="vertical">    <ListView        android:layout_width="match_parent"        android:id="@+id/list"        android:layoutAnimation="@anim/list_anim"        android:layout_height="match_parent"/>LinearLayout>

然而在运行的时候还是报了同样的错误,再仔细看错误提示
发现需要的是一个id为’android.R.id.list’的ListView控件

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical" android:layout_width="match_parent"    android:layout_height="match_parent">    <ListView        android:layout_width="match_parent"        android:layout_height="match_parent"        android:layoutAnimation="@anim/list_anim"        android:id="@android:id/list">ListView>LinearLayout>

最终程序完美运行

更多相关文章

  1. [置顶] android 自定义控件
  2. Android(安卓)Layout XML属性
  3. 关于基本控件TextView属性大全详解
  4. 第五课--位置布局
  5. Android(安卓)实用工具Hierarchy Viewer实战
  6. android:layout_alignParent 布局相对于父布局的位置
  7. Android中的常用控件之进度条(ProgressBar)
  8. Android(安卓)中自定义控件和属性(attr.xml,declare-styleable,T
  9. Android-x86-6.0定制之路 - 辛酸路开始

随机推荐

  1. Android 面试必备 - 知识图谱
  2. android 监控软键盘确定 搜索 按钮并赋予
  3. 初次体验Android,过程很艰辛!
  4. Android Animation学习笔记【原帖没有Dem
  5. 浅谈Android中MVC、MVP、MVVM模式(一)
  6. iPhone和Android,谁将成为赢家?
  7. android连接webapp发送接收消息最简实现
  8. android shape的使用详解
  9. sdcardFS(android sdcard存储方案---基于w
  10. Android中如何修改编译的资源ID值(默认值