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