我的安卓应用程序中有数据库方面的问题。我从不同的数据库中的许多地方遇到了这个异常:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.logtomobile.gmbclient/com.logtomobile.gmbclient.TransactionHistoryActivity}: android.database.sqlite.SQLiteCantOpenDatabaseException: unable to open database file (code 14)
我所有的数据库都使用扩展SQLiteOpenHelper的单例类。我还在使用后关闭了所有光标。出现这种异常的原因是什么?我该怎么办来解决问题?
在这个异常之前,我遇到了另一个SQLite异常:
(14) cannot open file at line 32473 of [00bb9c9ce4]
(14) os_unix.c:32473: (24) open(/data/data/com.logtomobile.gmbclient/databases/GmbDB-journal)
我无法粘贴我的代码,因为这个异常每次在代码中的不同位置抛出。 所有数据库都是在代码中创建的,而不是从外部文件导入的。 所有进行数据库查询的方法都是从DB Helpers中的同步方法调用的。 在Helpers中有静态Helper实例(单例),它们还具有成员SQLiteDatabase对象。 这些对象在Helper构造函数中通过getWritableDatabase()初始化一次,并保持打开状态而不关闭。 代码中的每个查询都是在这些SQLiteDatabase对象上调用的。
public synchronized static GmbDBHelper getInstance(Context context) {
if (sHelper == null) {
sHelper = new GmbDBHelper(context.getApplicationContext());
}
return sHelper;
}
private GmbDBHelper(Context context) {
super(context, GmbDB.DB_NAME, null, DB_VERSION);
mContext = context;
mDatabase = getWritableDatabase();
Log.d("DbHelper", "GmbDbHelper()");
}
synchronized SQLiteDatabase openDbForReading() {
return mDatabase;
}
synchronized SQLiteDatabase openDbForWriting() {
return mDatabase;
}
...