android.database.CursorIndexOutOfBoundsException:Index -1 requested, with a size of 1
2014-08-21 13:52
465 查看
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:
正确的用法:
android 中数据库处理,特别是使用cursor时,注意初始位置,好像是从下标为-1的地方开始的,也就是说一次查询中,返回给cursor查询结果时,不能够马上从cursor中提取值。
比如,下面的代码会返回错误,android.database.CursorIndexOutOfBoundsException:Index -1 requested, with a size of 0:
<pre name="code" class="prettyprint">Cursor curPath = localDbHelper.queryFromLocalMusicById(id);String path = curPath.getString(curPath.getColumnIndex(DBHelper.LOCAL_PATH));
正确的用法:
Cursor curPath = localDbHelper.queryFromLocalMusicById(id); String path = null; if(curPath != null&&curPath.moveToFirst()){ path = curPath.getString(curPath.getColumnIndex(DBHelper.LOCAL_PATH)); }
相关文章推荐
- android.database.CursorIndexOutOfBoundsException: Index <m> requested, with a size of <n>
- android.database.CursorIndexOutOfBoundsException:Index -1 requested, with a size of 1(zz)
- 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
- android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1
- android.database.CursorIndexOutOfBoundsException: Index 5 requested, with a size of 5
- Android 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 14
- qlite操作时出现下面错误 android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of
- android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 3
- Caused by: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 2
- 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 <m> requested, with a size of <n>
- android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
- android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0