We have a sqlite database in our Application. Its working fine for all the users but few of them experiencing the Caused by: android.database.sqlite.SQLiteException: n
In my case I changed my db name and its work for me
try remove getReadableDatabase
if (!dbExist) {
synchronized (this) {
db_Read = this.getReadableDatabase();
Log.e("Path 2", this.getReadableDatabase().getPath());
db_Read.close();
copyDataBase();
Log.v("copyDataBase---", "Successfully");
}
to
if (!dbExist) {
synchronized (this) {
//db_Read = this.getReadableDatabase();
// Log.e("Path 2", this.getReadableDatabase().getPath());
// db_Read.close();
copyDataBase();
Log.v("copyDataBase---", "Successfully");
}
The problem is because some of device is upgrading your app, so the checkDataBase()
returning true
, so you are not calling copyDataBase()
. So you are using previous database which doesn't have generalSettings
table.
To solve this try:
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if(newVersion>oldVersion)
copyDatabase();
}
and also update your constructor:
public InstallDB(Context context, String name) {
super(context, name, null, DB_VERSION);
// DB_VERSION is an int,update it every new build
this.ctx = context;
this.DBNAME = name;
this.DBPATH = this.ctx.getDatabasePath(DBNAME).getAbsolutePath();
Log.e("Path 1", DBPATH);
}
it is another solution to this problem some time developer didnot knows that there is not space between column name and its end like KEY_ADDRESS, this is wrong approach use space between comma and name of attribute