android 出现Make sure the Cursor is initialized correctly before accessing data from it

Make sure the Cursor is initialized correctly before accessing data from it

详细错误是:java.lang.IllegalStateException: Couldn't read row 0, col 2 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.

出现这个原因是因为我在获取Cursor中的字段时,获取了一个不存在的字段,例如,我原本要获取数据库book表中的bookId字段,结果获取的时候写成了bookiD,

while (cursor.moveToNext()) {  
 int bookId = cursor.getInt(cursor.getColumnIndex("bookiD"));
}

注意:Android是区分大小写的,所以我们在获取的时候也要严格按照数据库表字段的大小写来获取数据

 



qq3061280@163.com
原文地址:https://www.cnblogs.com/aibuli/p/2c143a1440c9d1b21b58e65a07eb0ef8.html