Android SimpleCursorAdapter No such column Id

后端 未结 4 536
囚心锁ツ
囚心锁ツ 2021-01-20 18:31

I have a Listview that I want to populate with information from my SQLite database with and this seemed like the most practical solution. In my debugger it says it\'s caused

相关标签:
4条回答
  • 2021-01-20 18:42

    It means either column name "name" or "data" does not exist in your database table. Can you publish the table schema? Are these column names available?

    0 讨论(0)
  • 2021-01-20 18:52

    SimpleCursorAdapter always need a _id field .

    Your database contains table without id column or id with other column name . so uninstall app . and edit CREATE statement as :

      "CREATE TABLE IF NOT EXISTS contact_data( _id INTEGER PRIMARY KEY AUTOINCREMENT,  something ,............ )
    
    0 讨论(0)
  • 2021-01-20 18:52

    Actually declaring the _id as suggested above will work "_id INTEGER PRIMARY KEY AUTOINCREMENT", but if you don't need _id to be unique over the life of the table, you can omit the AUTOINCREMENT keyword, as the "PRIMARY KEY" will also autoincrement, but is logically equivalently to (max(_id)+1), which guarantees uniqueness which is really what you want when using the CursorAdapter.

    0 讨论(0)
  • 2021-01-20 19:07

    You are not including _id in your column list for the query you do in getSpinnerData().

    FYI,

    You must be extending CursorAdapter which demand _id column.

    _id is used only in CursorAdapter to determine which column is id. You can override this behavior in CursorAdapter or add alias in query to id.

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