Mats Raemen
Mats Raemen

Reputation: 1812

Android error on unused column

I am building an app that creates and communicates with an SQLite database.

However, each time the app makes a connection with the database, it shuts down due to errors.

The (in my eyes) relevant errors are these:

03-21 07:50:29.308: E/AndroidRuntime(554): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dummies.android.taskreminder/com.dummies.android.taskreminder.ReminderListActivity}: java.lang.IllegalArgumentException: column '_id' does not exist

03-21 07:50:29.308: E/AndroidRuntime(554): Caused by: java.lang.IllegalArgumentException: column '_id' does not exist

In the tutorial I used, the ID column is named "_id" but i renamed it to "ReminderID" before ever using it. The term "_id" is never used in my version and renaming the variable "ReminderID" to "_id" gives me the same errors.

Upvotes: 0

Views: 73

Answers (3)

Android
Android

Reputation: 1427

_id column is not that you table you can pot this column or other remove to _id key in you query

Upvotes: 0

5hssba
5hssba

Reputation: 8079

Your database doesn't have to have a column called '_id' but the SimpleCursorAdaptor does need to have one returned. You can do this with an alias. _id field is used as a unique key to make sure the data the cursor handles can be handled correctly by adapters and adapterviews etc. if

ReminderID,XYZ ABC are your columns... then

To query for your SimpleCursorAdapter, you can do this with a database rawQuery...

 SELECT  ReminderID as _id,XYZ,ABC FROM MY_TABLE

Upvotes: 0

Snicolas
Snicolas

Reputation: 38168

_id is a convention on android, cursorAdapter needs it for instance.

Upvotes: 1

Related Questions