I\'m trying to debug my application on a real device but I get this error:
ERROR/AndroidRuntime(981): Caused by: java.lang.IllegalArgumentException:
I have had similar problem because I was not adding the _id column to the projection argument, so adding _id to the projections argument of the query was the solution. (commented by @nobugs)
Example:
String[] projections = {"_id", "name", "age"};
Cursor cursor = db.query(domainClass.getSimpleName(), projections,
null, null, null, null, null);
You are trying to use a cursor that REQUIRES a column called _id. Its as simple as editing your table creation statement and adding a column called _id.
Its declartion looks something like this:
_id INTEGER PRIMARY KEY AUTOINCREMENT
Add this and you will then be able to use it. I believe this is a requirement that is required in order to use a SimpleCursorAdapter.
UPDATE
"CREATE TABLE IF NOT EXISTS contact_data( _id INTEGER PRIMARY KEY AUTOINCREMENT, contact_id INTEGER, contact_name VARCHAR(50), number_type VARCHAR(50), contact_number VARCHAR(50), duration TIME, duration_sum TIME, date DATE, current_time TIME, cont INTEGER, type VARCHAR, month VARCHAR(50), day VARCHAR(50), year VARCHAR(50));"
Solution: add a space between the left parenthesis '(' and _id
I did this and solved my problem.
Before
SELECT id
After
SELECT id as _id
First of all uninstall the app, and then do following steps:
CursorAdapter always requires a _id
column to be present. So, in the list of projections used for creating Cursor, you need to add _id
column.