Android column '_id' does not exist?

前端 未结 8 955
野性不改
野性不改 2020-11-22 15:39

I\'m having trouble with something that works in the Notepad example. Here\'s the code from the NotepadCodeLab/Notepadv1Solution:

String[] from = new String[         


        
8条回答
  •  执笔经年
    2020-11-22 15:53

    This has been answered and I would like to make it more comprehensive here.

    SimpleCursorAdapter requires that the Cursor's result set must include a column named exactly "_id". Don't haste to change schema if you didn't define the "_id" column in your table. SQLite automatically added an hidden column called "rowid" for every table. All you need to do is that just select rowid explicitly and alias it as '_id' Ex.

    SQLiteDatabase db = mHelper.getReadableDatabase();      
    Cursor cur =  db.rawQuery( "select rowid _id,* from your_table", null);
    

提交回复
热议问题