开发者

Query didn't work

开发者 https://www.devze.com 2023-01-29 05:32 出处:网络
HI, I m using this query but it didn\'t work. It returns error 12-08 17:04:21.498: ERROR/AndroidRuntime(1867): android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1

HI, I m using this query but it didn't work. It returns error

12-08 17:04:21.498: ERROR/AndroidRuntime(1867): android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1

Cursor mCursor = dbRead.query(DBHandler.TABLE_NAME, new 开发者_JAVA技巧String[] {"LevelNumber", "LevelState" }, "LevelNumber = " + level_Number +"", null, null, null, null);

for(int i=0; i<mCursor.getCount(); i++) {
 levelNumber = mCursor.getString(0);
 levelState = mCursor.getString(1);
}


Your cursor isn't positionned. Cursor allows the user to iterate over results, but you need to tell it to iterate. So, a better way to do your loop would be :

for (mCursor.moveToFirst(); !mCursor.isAfterLast(); mCursor.moveToNext()) {
    levelNumber = mCursor.getString(0);
    levelState = mCursor.getString(1);
}


I think you need to add mCursor.moveToFirst() before for(int i = 0;...

http://developer.android.com/reference/android/database/Cursor.html#moveToFirst()

0

精彩评论

暂无评论...
验证码 换一张
取 消