1.在使用SimpleCursorAdapter adapter=new SimpleCursorAdapter
(this,R.layout.item,cursor,new String[]{"name","phone","amount"},new int[]
{R.id.name,R.id.phone,R.id.amount});这个SimpleCursorAdapter适配器的时候:
出现这个异常:
-----------------------------------------------
03-12 23:23:22.934: E/AndroidRuntime(23439): Caused by:
java.lang.IllegalArgumentException: column '_id' does not exist
--------------------------------------------------------------------
这个异常跟SimpleCursorAdapter ,这个源码有关:
可以查看源码,会有说明:
---------------------------
方法:1.把数据库表中的主键id改成:_id
2.处理查询后的结果集:主键起一个别名:
select personid as _id,name,phone,amount from person order by personid asc
limit ?,?
本文介绍了一种在使用SimpleCursorAdapter时遇到的_illegalArgumentException: column '_id' does not exist_异常,并提供了两种解决方案:一是修改数据库表中的主键名为_id;二是通过SQL查询时为_id字段设置别名。
4089

被折叠的 条评论
为什么被折叠?



