Android SimpleCursorAdapter No such column Id

柔情痞子 提交于 2019-12-01 22:13:54

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.

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 ,............ )

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?

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!