在使用ListViw的时候使用simpleCursorAdapter适配器显示sqlite数据,
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.persionitem, cursor, new String[{ "personid", "name", "age" }, new int[] {R.id.personid, R.id.name, R.id.age });
就出现 java.lang.IllegalArgumentException: column ‘_id’ does not exist 错误。
查询手册后,发现Cursor中未包含名为_id的列,SimpleCursorAdapter父类CursorAdapter的要求。
遇到这种情况,可以在查询语句中伪造一列名为_id的字段。
建议:sqlite的主键命名时,命名为_id,所以,当你用到sqlite的simpleCursorAdapter时,必须把数据表的主键命名为_id。

改动:1

String sql = "select personid as _id,name,age from person limit ?,?";

2 :SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.persionitem, cursor, new String[{ "_id", "name", "age" }, new int[] {R.id.personid, R.id.name, R.id.age });

更多相关文章

  1. android适配器的简单使用
  2. android 检测sqlite数据表和表中字段(列)是否存在 (转)
  3. 打造Android万能适配器Adapter
  4. android 适配器里面的按钮点击切换
  5. Android性能:经典ListView适配器convertView缓存及复用机制
  6. 一个功能强大的RecyclerViewAdapter 适配器 BaseRecyclerViewAda
  7. android操作sqlite3的blob字段,显示数据中的图片

随机推荐

  1. Android一些常用的颜色值
  2. 10 Alternative Android(安卓)App Stores
  3. Android(安卓)加密解密
  4. Spinner选择框应用
  5. Android~~布局Layout
  6. android拍照相册工具类
  7. Android带进度条文件上传
  8. Android(安卓)GPS基础
  9. Android获取验证码倒计时
  10. Android(安卓)UI开发的基础