I am trying to learn about SQLite databases, but I really hate dealing with any back-end stuff, with a passion. I\'m already hitting walls with a seemingly simple problem. <
If for some reason, you dropped the table, you might want to delete the database to force the application to recreate it correctly. Use adb shell
and find the database in /data/data/[package_name]/databases/
. You can just delete the file.
Make sure that onCreate
method called. I am also facing similar type of problem when creating multiple table. If you create a separate class make sure you first clear all the storage data of your app and then again run it ..It will work fine for me.
try this one for example for insert:
public boolean insertBook(String title, String author, String isdn) {
try {
SQLiteDatabase db = getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(TITLE, title);
cv.put(AUTHOR, author);
cv.put(ISBN, isdn);
***try
{
db.insert(TABLE_NAME, null, cv);
}
catch ( SQLiteException e)
{
onCreate(db);
db.insert(TABLE_NAME, null, cv);
}***
db.close();
return true;
} catch (Exception exp) {
exp.printStackTrace();
return false;
}
}
I had this problem, but cleaning the project did not fixed it.
It turned out I passed DATABASE_NAME
instead of TABLE_NAME
.
Note:
External Database You Access Time must add for the path in Sqliteopenhelper class
public final static String DATABASE_PATH = "/data/data/com.example.shortcuts/databases/";
com.example.shortcuts=Your Package name
Nothing about this made any sense, as the table existed from the very beginning of the DB, so we tried different things:
uninstalling app
claning cache / data
changing database version number
forcing to copy the database even if it already existed