【问题标题】:Android SQLite database exception - code 14 (unable to open database file)Android SQLite 数据库异常 - 代码 14(无法打开数据库文件)
【发布时间】:2013-11-04 14:09:07
【问题描述】:

我的 android 应用程序中的数据库有问题。我在不同数据库的很多地方都得到了这个异常:

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 对象。这些对象由 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;
}

...

【问题讨论】:

  • 可能您的数据库已被其他查询/事务锁定
  • 请发布您的代码。您发布的日志跟踪也不完整。它不会告诉在哪一行抛出异常。
  • 你解决了这个问题吗?我有类似的问题,无法复制自己,但会从不同的用户和地点获得大量报告。
  • 你解决了这个问题吗?然后添加答案,因为很多人都有这个问题。

标签: android sqlite exception


【解决方案1】:

请检查清单中的权限。并添加以下内容以防您错过。

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-03
    • 2016-06-22
    • 2014-04-28
    • 1970-01-01
    相关资源
    最近更新 更多