Android. Sqlite Exception: No Such Column _id
Solution 1:
If you created database for example with fields 'a', 'b' and 'c' and used this db then if you add new field (for ex. 'd') you need to recreate database on phone (just delete it).
Solution 2:
You probably don't have a column _id in your database table. Pull the database and open it with SqliteViewer to check if it actually exists. The database is usually under /data/data/com.yourapp.package/databases/
You can use: http://sqlitebrowser.sourceforge.net/ or http://www.navicat.com/en/products/navicat_sqlite/sqlite_overview.html (they also have a free lite version)
Solution 3:
Try rowid
instead of _id
. It works for me.
Solution 4:
Right, you should create the database table before querying on it.
Here is an example:
privatestaticfinalStringDATABASE_CREATE_DRIVERS="create table " + DATABASE_TABLE_DRIVERS + "(" + KEY_ROWID +" integer primary key autoincrement, "
+ KEY_DRIVERID + " text not null,"
+ KEY_FIRST_NAME + " text not null,"
+ KEY_LAST_NAME + " text not null,"
+ KEY_SPEED_LIMIT + " int not null,"
+ KEY_TIMESTAMP + " int"
+ ");";
Then query on it here:
publicCursorfetchAllDrivers(){
Cursor mCursor =
mDb.query(true, DATABASE_TABLE_DRIVERS, newString[] {
KEY_ROWID,
KEY_DRIVERID,
KEY_FIRST_NAME,
KEY_LAST_NAME,
KEY_SPEED_LIMIT,
KEY_TIMESTAMP},"", null,null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
It also appears that you are missing a sixth argument as to what you are querying for. See where I put "" in method parameter string.
Solution 5:
This is can exists 2 possiblities:
- This problem can occurred from broken SQLite schema.
Your question is not about SQL Statement problem. but many developer can think SQL Statement problem about your question.
This case can check no demaged data in your database file. Although you can not use select fields and sql where clause by field name.
As a result, you can not use database file in your android code.
Exactly solution, I recommend recreate SQLite DB file, step by step.
You must be backup before use SQLite modification tool. (SQLite Manager, Browser, others db manage tools)
- This problem occurred from your persistent data.
If you use the same file name for assets or raw data when run with modified data,
you can try uninstall previous installed app for refresh.
Post a Comment for "Android. Sqlite Exception: No Such Column _id"