嘿,我的代码中出现了索引越界错误。
从活动中:
Cursor cursor = mDbHelper.fetchA(b);
@SuppressWarnings("static-access")
int a = (int) cursor.getDouble(cursor.getColumnIndex(mDbHelper.KEY_I));
cursor.close();我的数据库适配器:
public Cursor fetchA(String b){
return mDb.query(DATABASE_TABLE, new String[] {KEY_I}, "b=\""+B+"\"", null, null, null, null);
}错误:
E/AndroidRuntime( 5766): FATAL EXCEPTION: main
E/AndroidRuntime( 5766): android.database.CursorIndexOutOfBoundsException: Index
-1 requested, with a size of 1我该如何解决这个问题呢?
发布于 2012-01-04 04:53:55
游标开始指向第一行之前的位置。因此,您需要将光标移动到第一行,然后才能获取数据。应该由Cursor#moveToFirst()或#moveToNext()来完成这项工作。
Cursor cursor = mDbHelper.fetchA(b);
cursor.moveToNext();
@SuppressWarnings("static-access")
int a = (int) cursor.getDouble(cursor.getColumnIndex(mDbHelper.KEY_I));
cursor.close();发布于 2012-01-04 05:20:14
Cursor cursor = mDbHelper.fetchA(b);
startManagingCursor(cursor);
cursor.moveToNext();
.......这是你的检索代码。
https://stackoverflow.com/questions/8718446
复制相似问题