问题描述:
rawQuery查询如果你要查询的表的主键字段名不是"_id",则会报IllegalArgumentException错误:
03-11 22:02:39.876: E/AndroidRuntime(2130): Caused by: java.lang.IllegalArgumentException: column ‘_id‘ does not exist,
03-11 22:02:39.876: E/AndroidRuntime(2130): at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:303)
解决办法:
方法一:修改表结构,将主键字段名修改为"_id"(不推荐,因为牵连修改太多)
方法二:给主键字段取别名,例如:
cursor = db.rawQuery("select u_id as _id ,u_name,sex,amount from t_user", null);
时间: 2024-10-09 14:37:57