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

时间:2014-10-17 23:17:55   收藏:0   阅读:8377
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是区分大小写的,所以我们在获取的时候也要严格按照数据库表字段的大小写来获取数据

 

来自为知笔记(Wiz)


评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!