android.database.CursorIndexOutOfBoundsException:Index -1 requested, with a size of 0
来源:互联网 发布:北美吐槽君 知乎 编辑:程序博客网 时间:2024/04/30 18:28
【解决】android.database.CursorIndexOutOfBoundsException:Index -1 requested, with a size of 0
android 中数据库处理,特别是使用cursor时,注意初始位置,好像是从下标为-1的地方开始的,也就是说一次查询中,返回给cursor查询结果时,不能够马上从cursor中提取值。
比如,下面的代码会返回错误,android.database.CursorIndexOutOfBoundsException:Index -1 requested, with a size of 0:
int score = ((Cursor)getReadableDatabase().query(TABLE_NAME, new String[]{"learned"}, "_id=?", new String[]{""+id}, null, null, null,"1")).getInt(0);
正确的用法:
Cursor cursor = getReadableDatabase().query(TABLE_NAME, new String[]{"learned"}, "_id=?", new String[]{""+id}, null, null, null,"1");
int learned=0;
if(cursor.moveToFirst()){
score= cursor.getInt(0);
}
cursor.close();
- android.database.CursorIndexOutOfBoundsException:Index -1 requested, with a size of 0
- Android开发7——android.database.CursorIndexOutOfBoundsException:Index -1 requested, with a size of 1
- android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
- android.database.CursorIndexOutOfBoundsException:Index -1 requested, with a size of 1
- android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1
- android.database.CursorIndexOutOfBoundsException:Index -1 requested, with a size of 1
- android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1
- android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1
- android.database.CursorIndexOutOfBoundsException:Index -1 requested, with a size of 1
- android.database.CursorIndexOutOfBoundsException:Index -1 requested, with a size of 1
- android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 3
- Caused by: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 2
- qlite操作时出现下面错误 android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of
- android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 14
- android.database.CursorIndexOutOfBoundsException: Index <m> requested, with a size of <n>
- android.database.CursorIndexOutOfBoundsException: Index 5 requested, with a size of 5
- android.database.CursorIndexOutOfBoundsExcept: Index -1 requested, with a size of 1
- cursor使用错误(android.database.CursorIndexOutOfBoundsException: Index -1 requested)
- 鸟哥私房菜--第13章 学习 Shell Scripts(4)
- 哈佛案例课
- PiscisOS开发笔记_1_PiscisOS的诞生和系统特性简介
- javaWeb中request获取请求数据的方式。
- C#异步调用四大方法详解
- android.database.CursorIndexOutOfBoundsException:Index -1 requested, with a size of 0
- ASIHTTPRequest 详解, http 请求终结者
- 如何让你的网站瘦身而保持营养
- 谁是行内谁是块级
- Liferay's Permission 权限
- 实现JSP数据和JavaScript数据交互使用
- JSP内置对象
- 谷歌400多名科学家团队项目:让机器看懂视频
- C++ 后台程序实时性能监控