0

I've got a simple quiz app that's works with 3 possible answers but not with 4. The app crashes with the following error: java.lang.IllegalStateException: Couldn't read row 0, col 6 from CursorWindow.

The only code which references a cursor is this:

public List<Question> getAllQuestions() {
    List<Question> quesList = new ArrayList<Question>();

    String selectQuery = "SELECT  * FROM " + TABLE_QUEST;
    dbase = this.getReadableDatabase();
    Cursor cursor = dbase.rawQuery(selectQuery, null);

    while (cursor.moveToNext()) {
        Question quest = new Question();
        quest.setID(cursor.getInt(0));
        quest.setQUESTION(cursor.getString(1));
        quest.setANSWER(cursor.getString(2));
        quest.setOPTA(cursor.getString(3));
        quest.setOPTB(cursor.getString(4));
        quest.setOPTC(cursor.getString(5));
        quest.setOPTD(cursor.getString(6));
        quesList.add(quest);
    }

    return quesList;
}

This is different from another general question about how to set up android databases. Here I'm trying to track down a specific error regarding CursorWindow.

The functions for the database table (DbHelper class) are here:

@Override
public void onUpgrade(SQLiteDatabase db, int oldV, int newV) {

    db.execSQL("DROP TABLE IF EXISTS " + TABLE_QUEST);

    onCreate(db);
}

Context context;
private static final int DATABASE_VERSION = 13;

private static final String DATABASE_NAME = "mathsone";
private static final String TABLE_QUEST = "quest";
private static final String KEY_ID = "qid";
private static final String KEY_QUES = "question";
private static final String KEY_ANSWER = "answer";
private static final String KEY_OPTA = "opta";
private static final String KEY_OPTB = "optb";
private static final String KEY_OPTC = "optc";
private static final String KEY_OPTD = "optd";

private SQLiteDatabase dbase;

public DbHelper(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
    this.context = context;
}

@Override
public void onCreate(SQLiteDatabase db) {
    dbase = db;
    String sql = "CREATE TABLE IF NOT EXISTS " + TABLE_QUEST + " ( "
            + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_QUES
            + " TEXT, " + KEY_ANSWER + " TEXT, " + KEY_OPTA + " TEXT, "
            + KEY_OPTB + " TEXT, " + KEY_OPTC + " TEXT, " + KEY_OPTD + " TEXT)";
    db.execSQL(sql);
    addQuestion();
}

0 Answers0