sqlite db exception:无法打开数据库

时间:2015-06-12 11:40:01

标签: android sql android-sqlite

运行我的应用程序时出现以下错误:

'/data/data/in.acme.www.solarproject/databases/SolarDatabase.sqlite'.
    android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
            at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
            at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:209)
            at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
            at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
            at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
            at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
            at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:807)
            at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:792)
            at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:697)
            at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:672)
            at in.acme.www.solarproject.database.DBHelper.checkDataBase(DBHelper.java:81)
            at in.acme.www.solarproject.database.DBHelper.createDataBase(DBHelper.java:49)

    try{
        String myPath = DATABASE_PATH + DATABASE_NAME;
        checkDB = SQLiteDatabase.openDatabase(myPath, null,
                SQLiteDatabase.OPEN_READWRITE);  // (DBHelper.java:81)

    }catch(SQLiteException e){
        //TODO: Add exception
        e.printStackTrace();
    }

我已将我的数据库复制到资产文件夹,来自他们对getDbrecords()的查询

SQLiteDatabase mReadableDB= mDbHelper.getReadableDatabase();
try{
    mCursor=mReadableDB.rawQuery("SELECT * FROM DepartmentMaster ",null); 

从那里出现异常。请帮忙解决。

1 个答案:

答案 0 :(得分:0)

你可以尝试几件事:

  1. 尝试使用SQLiteBrowser打开它以查看它没有损坏
  2. 确保它在正确的路径
  3. 确保它具有正确的读/写权限
  4. 确保您在清单文件<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  5. 中拥有此权限