I get this weird exception when i run my app on both the emulator and a USB connected device. i can see the table inside the shell, but when I try to insert a record from the Activity acton I get this exception:
android.database.sqlite.SQLiteException: table audios has no column named downloaded
I am mostly running on an emulator with Android 1.5. The predominant part of my code is linked to this tutorial – http://www.devx.com/wireless/Article/40842/1954.
This is the create statement I use:
private static final String DATABASE_CREATE =
"create table audios ( _id integer primary key autoincrement, "
+ "user_name text not null, title text not null, file_path text not null, download integer not null, "
+ "created_at integer not null, downloaded_at integer not null );";
This is the insert code I use:
//--- insert a title into the database ---
public long insertTitle(String user_name, String title, String file_path, Integer downloaded, long created_at, String downloaded_at ) {
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_USER_NAME, user_name);
initialValues.put(KEY_TITLE, title);
initialValues.put(KEY_FILE, file_path);
initialValues.put(KEY_DOWNLOADED, downloaded);
initialValues.put(KEY_CREATED_AT, created_at);
initialValues.put(KEY_DOWNLOADED_AT, downloaded_at);
return db.insert(DATABASE_TABLE, null, initialValues);
}
I will hazard a guess that you have this in your code:
The reason for the error message is that…
Really. It doesn’t, just as the error message says.
If you re-read your table-creation SQL, you’ll notice that the column name is actually
download, notdownloaded.So correct your code to use the correct column name and you should be set. Note that correcting the code could mean either:
downloadedinstead of justdownload. Personally I would go with this one, unless you have lots of other code already usingdownload, sincedownloadin my mind is eithera downloadorto download, nothas been downloaded, but it really depends on its actual meaning