I've got an app using sqlite on android. Everything works fine, I can create, read and write the database without any problems. BUT if I change the sourcecode in eclipse (doesn't matter what as long as it recompiles) the new apk is created and pushed to the emulator. Accessing the database now will result in
enter code here03-07 15:50:03.886: ERROR/AndroidRuntime(311): Caused by: android.database.sqlite.SQLiteException: file is encrypted or is not a databas开发者_如何学Pythone
Deleting the database file with the file explorer and accessing the database, will recreate the db and everything is fine again.
I'm sure the db is closed after every access.
I've found this error too! And Finally I've decided to create the DB file from my APP, executing some code like:
public class MyHelperSqliteHelper extends SQLiteOpenHelper{
// SQL to generate USER table
String sqlCreate = "CREATE TABLE 'user' " +
"('X_id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL , " +
"'D_name' VARCHAR);";
...
@Override
public void onCreate(SQLiteDatabase db) {
try {
db.execSQL(sqlCreate);
}catch (SQLException e) {
e.printStackTrace();
}
}
...
}
Next step is export this file from DDMS view to file and open that file with SQLite manager. Here you will can to import all your datas and another tables.
Final step only need to export this database from SQLiteManager and if you open this file you can see it is encrypted.
I know this is a temporal solution but It can solve this problem, and you only need to do this one time and no more.
Good luck!
精彩评论