dimanche 8 mai 2016

RuntimeException - java.lang.IllegalArgumentException: column '_id' does not exist [duplicate]

In my app I'm trying to read data from a table in my DB, which is created as follows:

public DBHelper(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
    String createDreamTable = String.format("CREATE TABLE IF NOT EXISTS %s" +
            "( %s INTEGER PRIMARY KEY AUTOINCREMENT, " +
            "%s VARCHAR, " +
            "%s TEXT);",
            DreamContract.Dream.DREAM_TABLE_NAME,
            DreamContract.Dream._ID,
            DreamContract.Dream.COLUMN_NAME_DREAM_TITLE,
            DreamContract.Dream.COLUMN_NAME_DREAM_CONTENT);
    Log.d("avirankatz", createDreamTable);
    db.execSQL(createDreamTable);
}

When I try to get data from DB using GetDreamTitles, as seen below, I get java.lang.IllegalArgumentException: column '_id' does not exist

public Cursor getDreamTitles() {
    return getReadableDatabase().rawQuery(String.format("SELECT %s FROM %s", DreamContract.Dream.COLUMN_NAME_DREAM_TITLE, DreamContract.Dream.DREAM_TABLE_NAME), null);
}

EDIT:

DreamContract.Dream:

public static abstract class Dream implements BaseColumns {
    public static final String DREAM_TABLE_NAME = "dreamDiary";
    public static final String COLUMN_NAME_DREAM_TITLE = "title";
    public static final String COLUMN_NAME_DREAM_CONTENT = "dreamContent";
}

Aucun commentaire:

Enregistrer un commentaire