Im having some troubles trying to get the info stored in my database and showing it in a ListView.
This is the ListActivity where i want to show the rows:
Right, you should create the database table before querying on it.
Here is an example:
private static final String DATABASE_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:
public Cursor fetchAllDrivers(){
Cursor mCursor =
mDb.query(true, DATABASE_TABLE_DRIVERS, new String[] {
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.
This is can exists 2 possiblities:
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)
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.
i change my database name, all lower_caps. it worked for me.
Try rowid
instead of _id
. It works for me.
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)
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).