2013-11-04 106 views
4

我的Android應用程序中的數據庫有問題。我在很多地方得到這個例外,從不同的數據庫:Android SQLite數據庫異常 - 代碼14(無法打開數據庫文件)

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 Helper中的同步方法調用的。在Helpers中有靜態的Helper實例(singleton),也有成員SQLiteDatabase對象。這些對象通過getWritableDatabase()在Helper構造函數中初始化一次,並始終保持打開狀態而不關閉它們。代碼中的每個查詢都在這些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; 
} 

... 
+0

也許您的數據庫被其他查詢/交易鎖定 – waqaslam

+0

請發佈您的代碼。此外,您發佈的日誌跟蹤不完整。它不會告訴哪一行異常被拋出。 – Nitish

+1

你解決了這個問題嗎?我有類似的問題,不能複製自己,但從不同的用戶和地方得到噸的報告。 – katit

回答

0

請檢查清單中的權限。並添加以下內容以防萬一您錯過了。

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
相關問題