android中SimpleCursorAdapter _id错误的问题
2013-12-11 00:18
483 查看
android中SimpleCursorAdapter _id错误的问题
作为一个android新手,在绑定数据的时候是这样的
查询语句
这个时候运行总是报错,其中有一行
缺少了一列_id。
_id是用来干什么的?
SimpleCursorAdapter只识别_id作为主键
所以我们需要把上面查询的代码修改一下,添加一个_id的值,如果你的数据库中没有的话可以将主键 as _id。
作为一个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"}, 4000 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学习之适配器SimpleCursorAdapter
- android的adapter:ArrayAdapter,SimpleAdapter,SimpleCursorAdapter
- android SimpleCursorAdapter的使用
- 使用详解及源码解析Android中的Adapter、BaseAdapter、ArrayAdapter、SimpleAdapter和SimpleCursorAdapter
- 【android】ListView+SimpleCursorAdapter+checkbox实现批量删除
- android ListView使用的三种方法汇总(通过继承BaseAdapter,使用SimpleAdapter和SimpleCursorAdapter)
- simplecursoradapter使用时提示column '_id' does not exist
- android 的sqlite 主键与simpleCursorAdapter
- android]ListView+SimpleCursorAdapter+checkbox实现批量删除
- Android SimpleAdapter,SimpleCursorAdapter,ArrayAdapter的区别
- Android 之 SimpleCursorAdapter
- 【android】Cursor记录集游标、ListView和SimpleCursorAdapter、ListView数据动态更新
- Android新手入门2016(9)--ListView之SimpleAdapter和SimpleCursorAdapter
- Android ListView SimpleAdapter ArrayList 数据更新问题
- android SQlite结合SimpleCursorAdapter的简单使用
- android 中关于SimpleAdapter构造参数的问题。
- Android-Adapter实现方法(ArrayAdapter,SimpleAdapter,SimpleCursorAdapter)