2

我已经通过 SO 和谷歌搜索,但似乎不适合我的情况。我的应用程序从多个用户日志中随机给了我这个异常,当我在模拟器或我的设备中测试它时从未发生过。(我在 Galaxy tab2 10.1 ,android OS 4.1.1 上运行。)我测试它可以从成功运行开发。所需的 android 清单权限已到位。以下是我的代码和堆栈跟踪

堆栈跟踪 :

android.database.sqlite.SQLiteCantOpenDatabaseException: unable to open database file (code 14) 
android.database.sqlite.SQLiteConnection.nativeExecute(Native Method)                   
android.database.sqlite.SQLiteConnection.execute(SQLiteConnection.java:678)                     
android.database.sqlite.SQLiteSession.beginTransactionUnchecked(SQLiteSession.java:323)                     
android.database.sqlite.SQLiteSession.beginTransaction(SQLiteSession.java:298)                      
android.database.sqlite.SQLiteDatabase.beginTransaction(SQLiteDatabase.java:505)                        
android.database.sqlite.SQLiteDatabase.beginTransaction(SQLiteDatabase.java:416)                        
com.framework.dataaccess.GenericDAO.start(GenericDAO.java:78)       

下面是我实例化 SQLitedatabase 的单例

protected static GenericDAO getInstance(Context ctx, String sql) {

  if (instance == null) {
            try {
                instance = new GenericDAO(ctx, sql);
            } 
            catch (Exception e) { e.printStackTrace(); }
        }

        if(db == null || !db.isOpen()){
            try {
                db = instance.getWritableDatabase();

            } 
         catch (Exception e) { e.printStackTrace(); }   

        }

        return instance;
 }

对于插入、删除或更新操作,我将放入这些 start() 和 commit()。

public void start() throws Exception{
        try{
            db.beginTransaction();
        }catch(Exception e){ 
            e.printStackTrace();
            throw e;
        }
    }

public void commit()  throws Exception{
    try{
        db.setTransactionSuccessful();
    }
    catch(Exception e){ 
        e.printStackTrace();
        throw e;
    }
    finally{
      db.endTransaction();      
    }

}


  public Cursor select(String table, String[] columns, String criteriaColValue){
     return db.query(true, table, columns, criteriaColValue, null, null, null, null, null); 
    }

我的代码从下面的 dao 选择中抛出异常。它不调用“start()”方法。

 public  ArrayList<Obj> getObjList(){


           ChildDao dao                = null;
           Cursor cursor               = null;
           ArrayList<Obj> list = new  ArrayList<Obj>();

            try{
                 dao = new childDao(context);
                 cursor = dao.select(TABLE_NAME, columns, Criterea );   

                 if(cursor!=null && cursor.moveToFirst()){
                    do{
                      list.add(myObjs);
                    } while(cursor.moveToNext());
                 }

            }catch(Exception ex){
                ex.printStackTrace();

            }
            finally{
                if(cursor!=null)cursor.close();
             }
          return list;
         }

我不知道错误是如何发生的,并且无法从开发环境中重现它。谁能给我一个指南在哪里调查?提前致谢。

4

1 回答 1

1

This may be a little late, but hope this can give a clue for whoever gets this problem. I also had a similar hard to reproduce exception:

unable to open database file (code 14)
    android.database.sqlite.SQLiteCantOpenDatabaseException: unable to open database file (code 14)
    at android.database.sqlite.SQLiteConnection.nativeExecuteForCursorWindow(Native Method)
    at android.database.sqlite.SQLiteConnection.executeForCursorWindow(SQLiteConnection.java:845)

It could be not because of database but has to do with extra data/files allocation somewhere in an application. In my case it was bad SoundPool code. Here are the details:

java.lang.RuntimeException: Could not read input channel file descriptors from parcel

于 2015-01-07T05:31:58.010 回答