我有一个使用 sqlite db 的应用程序,在第一次安装时我检查是否存在数据库文件夹或 db 文件如果不调用 updateDB 函数。但在某些情况下,例如 Galaxy Note 10.1 它给了我错误。
负载 ;
this.dhn = DataHelper.getDataHelper(this);
File directory = new File(Environment.getDataDirectory() + File.separator + "data" + File.separator + "XXX" + File.separator + "databases");
if(!directory.exists())
{
directory.mkdirs();
updateDB();
}
try {
androidCheckout = this.dhn.Guid();
if(this.dhn.getSettings("dbVersion") == null || Integer.parseInt(this.dhn.getSettings("dbVersion")) != Version || !this.dhn.isTableExists("UserInfo"))
{
updateDB();
}
}
catch (SQLiteException e)
{
try {
updateDB();
androidCheckout = this.dhn.Guid();
}
catch (SQLiteException e11)
{
ManuelYukle();
}
}
public void updateDB()
{
this.dhn.close();
try {
InputStream myInput;
myInput = getAssets().open("XXX.db");
// Path to the just created empty db
String outFileName = "/data/data/XXX/databases/"
+ "XXX.db";
// Open the empty db as the output stream
FileOutputStream myOutput = new FileOutputStream(outFileName);
// transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer)) > 0) {
myOutput.write(buffer, 0, length);
}
myOutput.flush();
myOutput.close();
myInput.close();
buffer = null;
outFileName = null;
this.dhn.close();
this.dhn = null;
this.dhn = DataHelper.getDataHelper(this); <<<<<<<< HERE IT CRUSHS
} catch (IOException e1) {
e1.printStackTrace();
}
}
DBHELPER 课程 >
private static DataHelper singleton;
public static DataHelper getDataHelper(Context context) {
if (singleton == null) {
singleton = new DataHelper(context);
OpenHelper openHelper = new OpenHelper(singleton.context);
singleton.db = openHelper.getWritableDatabase();
}
if(!singleton.db.isOpen()){
OpenHelper openHelper = new OpenHelper(singleton.context);
singleton.db = openHelper.getWritableDatabase();
}
singleton.context = context;
return singleton;
}
private DataHelper(Context context) {
this.context = context;
}
错误日志文件 >
12-09 19:11:15.772: I/SqliteDatabaseCpp(6271): sqlite returned: error code = 11, msg = database corruption at line 48171 of [ed759d5a9e], db=/data/data/XXX/databases/XXX_db
12-09 19:11:15.772: I/SqliteDatabaseCpp(6271): sqlite returned: error code = 11, msg = database disk image is malformed, db=/data/data/XXX/databases/XXX_db
12-09 19:11:15.772: E/SqliteDatabaseCpp(6271): sqlite3_exec - Failed to set synchronous mode = 1(Normal)
12-09 19:11:15.772: I/SqliteDatabaseCpp(6271): sqlite returned: error code = 11, msg = database corruption at line 48171 of [ed759d5a9e], db=/data/data/XXX/databases/XXX_db
12-09 19:11:15.772: I/SqliteDatabaseCpp(6271): sqlite returned: error code = 11, msg = database disk image is malformed, db=/data/data/XXX/databases/XXX_db
12-09 19:11:15.772: E/SqliteDatabaseCpp(6271): CREATE TABLE android_metadata failed
12-09 19:11:15.777: E/DefaultDatabaseErrorHandler(6271): Corruption reported by sqlite on database: /data/data/XXX/databases/XXX.db
12-09 19:11:15.782: E/DefaultDatabaseErrorHandler(6271): deleting the database file: /data/data/XXX/databases/XXX.db