android.database.CursorIndexOutOfBoundsException:Index -1 requested, with a size of 1
来源:互联网 发布:linux 网络编程 pdf 编辑:程序博客网 时间:2024/05/16 04:41
android.database.CursorIndexOutOfBoundsException:Index -1 requested, with a size of 1
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开发7——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 1
- android.database.CursorIndexOutOfBoundsException:Index -1 requested, with a size of 0
- 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.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
- android.database.CursorIndexOutOfBoundsExcept: Index -1 requested, with a size of 1
- cursor使用错误(android.database.CursorIndexOutOfBoundsException: Index -1 requested)
- 开启Nginx gzip压缩功能
- 大型数据库的设计原则与开发技巧
- 光棍节程序员闯关秀
- android获取电话号码实例
- codeforces 315B
- android.database.CursorIndexOutOfBoundsException:Index -1 requested, with a size of 1
- Patient Orientation(0020.0020)的理解,DR和乳腺(MG)的挂片协议
- IE6PNG图片无法透明解决方法
- JAVA 内存详解 (理解 JVM 如何使用 Windows 和 Linux 上的本机内存)
- 汇编语言的本质
- Informatica Scheduler调度
- 黑马程序员 -->齐头并进完成任务--多线程(上)
- ui-router中的sref还不支持动态绑定
- Windows中文件分隔符使用什么?