我的应用程序崩溃
java.lang.RuntimeException: Unable to start activity ComponentInfo{...}:
java.lang.IllegalStateException: Couldn't read row 0, col 1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
...下面是导致错误的方法:
public int getWeek(int yearAndWeek) throws CursorIndexOutOfBoundsException {
SQLiteDatabase db = this.getReadableDatabase();
String selectQuery = "SELECT * FROM " + TABLE_WEEKS + " WHERE "
+ KEY_WEEK + " = " + yearAndWeek;
Cursor c = db.rawQuery(selectQuery, null);
if (c.getCount() > 0)
c.moveToFirst();
return c.getInt(c.getColumnIndex(KEY_WEEK_NUMBER));
}此错误发生在这行return c.getInt(c.getColumnIndex(KEY_WEEK_NUMBER));中。请帮我解决这个问题。
发布于 2014-09-24 11:03:31
要从方法中保持正确的答复,您可以尝试使用以下代码。
public int getWeek(int yearAndWeek) throws CursorIndexOutOfBoundsException {
SQLiteDatabase db = this.getReadableDatabase();
String selectQuery = "SELECT * FROM " + TABLE_WEEKS + " WHERE " + KEY_WEEK + " = " + yearAndWeek;
Cursor c = db.rawQuery(selectQuery, null);
if (c.getCount() > 0) {
c.moveToFirst();
return c.getInt(c.getColumnIndex(KEY_WEEK_NUMBER));
}
return -1;
}https://stackoverflow.com/questions/26015144
复制相似问题