IllegalArgumentException: column '_id' does not exist when call to SimpleCursorAdaptor

前端 未结 4 1545
傲寒
傲寒 2020-12-16 20:28

I have a table named \"master\" with columns id, name, surname, gender, and designation

When I fire

4条回答
  •  不思量自难忘°
    2020-12-16 21:10

    This is happening because CursorAdapter must have an _id column in the table it is using.

    With the Database(SQLite) in Android applications, it is better to add a column named _id" to all tables in order to be able to use CursorAdapter.

    Alternatively, you can write an sql statement like

    select member_id as _id from member _table where ....." 
    

    in order to get a Cursor which may be used with CursorAdapter.

    This is specified in CursorAdaptor's documentation:

    Adapter that exposes data from a Cursor to a ListView widget. The Cursor must include a column named "_id" or this class will not work."

提交回复
热议问题