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

前端 未结 4 1541
傲寒
傲寒 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."

    0 讨论(0)
  • 2020-12-16 21:12

    Simple and Salty

    To overcome this problem, you have to rename the primary key field name as _id.

    0 讨论(0)
  • 2020-12-16 21:14

    Your namemaster tables needs to have a column _ID defined to be used by SimpleCursorAdaptor. Make sure your table schema includes _ID and not an id as the later is wrong.

    0 讨论(0)
  • 2020-12-16 21:24

    I believe the SimpleCursorAdapter assumes that there is a column '_id'. You need to create it so it would probably be easier for you to use "_id" instead of your own "id". Read the 2nd post on this page

    0 讨论(0)
提交回复
热议问题