前几天在使用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. 关于基本控件TextView属性大全详解
  3. Android Button控件 的简单使用(button监听和onClick触发函数使用
  4. adb错误:Failed to execute android command 'adb devices'.
  5. Android控件抖动效果
  6. Android瀑布流控件——AndroidStaggeredGrid
  7. 在Android当中常用的控件的详解和分析
  8. iOS和android解决键盘弹出遮挡控件的处理比较

随机推荐

  1. Android ble setCharactersticNotificati
  2. 戏说Android四大组件之Activity
  3. android之获得当前连接wifi的名字
  4. android中菜单的使用
  5. android获取屏幕长宽的方法
  6. Android属性动画完全解析(一)
  7. Android Uri转换成真实File路径
  8. Android(安卓)Surfaceflinger 的使用
  9. 【Android】SQLite数据库的简单使用
  10. Android自定义AlertDialog实现