使用以下代码创建和打开数据库失败:
mDatabase = SQLiteDatabase.openDatabase(mDatabaseFilePath,
null, DBFLAG);
SQLiteDatabase.openOrCreateDatabase(path, factory);
提示错误:
10-15 09:47:58.905: I/Database(507): sqlite returned: error code = 14, msg = cannot open file at source line 25502
10-15 09:47:58.905: E/Database(507): sqlite3_open_v2("/data/data/com.emile.salemanager/databases/salemanager.db", &handle, 6, NULL) failed
10-15 09:47:58.925: W/System.err(507): android.database.sqlite.SQLiteException: unable to open database file
原因是该API存在bug,解决方法:
mDatabase = this.openOrCreateDatabase(DBNAME,MODE_PRIVATE,null);
if(mDatabase != null)
{
mDatabase.close();
}
mDatabase = SQLiteDatabase.openDatabase(mDatabaseFilePath,
null, DBFLAG);