作为一个android新手,在绑定数据的时候是这样的

 ListView listview=(ListView)this.findViewById(R.id.listView1);                XJDal xj=new XJDal(MainActivity.this);         Cursor cur=xj.Query(); ListAdapter ad=new SimpleCursorAdapter(this, android.R.layout.simple_expandable_list_item_2, cur,new String[]{"timeflag","type"},                new int[]{android.R.id.text1,android.R.id.text2} );         listview.setAdapter(ad);

查询语句

 public Cursor Query() { return db.query("XJ", new String[]{"timeflag","type"}, null, null, null, null, null);  }

这个时候运行总是报错,其中有一行

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sclock/com.sclock.MainActivity}: java.lang.IllegalArgumentException: column '_id' does not exist


缺少了一列_id。

_id是用来干什么的?

SimpleCursorAdapter只识别_id作为主键

所以我们需要把上面查询的代码修改一下,添加一个_id的值,如果你的数据库中没有的话可以将主键 as _id。

 public Cursor Query() { return db.query("XJ", new String[]{"_id","timeflag","type"}, null, null, null, null, null);  }

更多相关文章

  1. Android 新手常见的10个误区(下)
  2. 强烈推荐Android新手的入门学习策略之一,Android Studio4使用配置
  3. Windows Phone 7 不温不火学习之《ListBox 数据与Android ListVi
  4. 【android工程转为lib工程后提示'R.id.xxx不能作为case语句的表

随机推荐

  1. 获取 + 查看 Android(安卓)源码的 方法
  2. Android(安卓)5.0 默认水波纹背景属性,可
  3. android颜色代码
  4. 【Android】:跳转系统界面汇总
  5. Android(安卓)控件GridView使用案例讲解
  6. 【Android】自定义权限
  7. Android(安卓)SDK Emulator: Compile Cya
  8. android FloatingActionButton
  9. android双击事件
  10. Android(安卓)NDK Tools 下载链接大全