2010-12-08 61 views
0

嗨,我使用此查詢,但它沒有奏效。它返回錯誤查詢沒有工作

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 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); 
} 

回答

2

您的光標未定位。遊標允許用戶遍歷結果,但你需要告訴它迭代。因此,一個更好的方式做你的循環是:

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

Thanx Valentin Rocher – Nuraiz 2010-12-10 07:17:09