android中SimpleCursorAdapter _id错误的问题
2013-06-21 11:54
435 查看
作为一个android新手,在绑定数据的时候是这样的
查询语句
这个时候运行总是报错,其中有一行
缺少了一列_id。
_id是用来干什么的?
SimpleCursorAdapter只识别_id作为主键
所以我们需要把上面查询的代码修改一下,添加一个_id的值,如果你的数据库中没有的话可以将主键 as _id。
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); }
相关文章推荐
- android中SimpleCursorAdapter _id错误的问题
- android小问题-------------SimpleCursorAdapter使用时的问题。 java.lang.IllegalArgumentException: column '_id' d
- 使用 SimpleCursorAdapter 时java.lang.IllegalArgumentException: column '_id' does not exist问题
- 使用详解及源码解析Android中的Adapter、BaseAdapter、ArrayAdapter、SimpleAdapter和SimpleCursorAdapter
- android 数据库存储+listView+SimpleCursorAdapter 范例demo(亲测)
- simpleCursorAdapter的一个问题
- Android train——ListView绑定ArrayAdapter、SimpleAdapter、SimpleCursorAdapter、BaseAdapter
- Android入门:ListView(SimpleCursorAdapter实现)
- Android的SimpleCursorAdapter出错
- android问题:布局文件控件自定义的ID错误
- Android SimpleCursorAdapter 绑定数据的陷阱
- 使用android.widget.SimpleAdapter.ViewBinder的一点问题!
- Android开发模板------自己定义SimpleCursorAdapter的使用
- Android API : SimpleCursorAdapter
- [Android] Adapter:SimpleAdapter SimpleCursorAdapter ArrayAdapter 与ListView的用法
- SimpleCursorAdapter和_id
- android播放器(music player)源码分析2(BaseExpandableListAdapter, SimpleCursorTreeAdapter
- Android SimpleAdapter 的list刷新问题。
- Android SimpleAdapter显示问题
- android中使用CursorAdapter和SimpleCursorAdapter的方法