I have a table named \"master\" with columns id
, name
, surname
, gender
, and designation
When I fire
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."
Simple and Salty
To overcome this problem, you have to rename the primary key field name as _id
.
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.
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