SQLiteOpenHelper getWritableDatabse()失败,没有异常

时间:2012-06-10 22:06:42

标签: android sqlite sqliteopenhelper

我有一个非常奇怪的问题。它只是在几台设备上不时显示。似乎无法在我想要的时候重现它,但有这么多次,我想我知道我从哪里得到它。

所以我有Loader通过单身SQLiteOpenHelper连接到sqlite:

try {
    Log.i(TAG, "Get details offline / db helper: "+DatabaseHelper.getInstance(getContext()));
    SQLiteDatabase db=DatabaseHelper.getInstance(this.getContext()).getWritableDatabase();
    Log.i(TAG, "Get details offline / db: "+db);
    //doing some work on the db...
} catch(SQLiteException e){
    e.printStackTrace();
    return null;
} catch(Exception e){
    e.printStackTrace();
    return null;
    //trying everything to grab some exception or whatever
}

我的SQLIteOpenHelper看起来像这样:

public class DatabaseHelper extends SQLiteOpenHelper { 

    private static DatabaseHelper mInstance = null;
    private static Context mCxt;

    public static DatabaseHelper getInstance(Context cxt) {
        //using app context as suggested by CommonsWare
        Log.i("DBHELPER1", "cxt"+mCxt+" / instance: "+mInstance);
        if (mInstance == null) {
            mInstance = new DatabaseHelper(cxt.getApplicationContext());
        }
        Log.i("DBHELPER2", "cxt"+mCxt+" / instance: "+mInstance);
        mCxt = cxt;
        return mInstance;
    }

    //private constructor
    private DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
        this.mCxt = context;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        //some tables created here
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        //upgrade code here
    }
}

在大多数情况下它真的很棒。但是我不时会得到类似这样的日志:

06-10 23:49:59.621: I/DBHELPER1(26499): cxtcom.myapp@407152c8 / instance: com.myapp.helpers.DatabaseHelper@40827560
06-10 23:49:59.631: I/DBHELPER2(26499): cxtcom.myapp@407152c8 / instance: com.myapp.helpers.DatabaseHelper@40827560
06-10 23:49:59.631: I/DetailsLoader(26499): Get event details offline / db helper: com.myapp.helpers.DatabaseHelper@40827560
06-10 23:49:59.631: I/DBHELPER1(26499): cxtcom.myapp@407152c8 / instance: com.myapp.helpers.DatabaseHelper@40827560
06-10 23:49:59.651: I/DBHELPER2(26499): cxtcom.myapp@407152c8 / instance: com.myapp.helpers.DatabaseHelper@40827560

此行Log.i(TAG, "Get details offline / db: "+db);永远不会被调用!没有例外,沉默。另外,Loader的线程不再运行了。

所以没有什么可以超越这条线:

SQLiteDatabase db=DatabaseHelper.getInstance(this.getContext()).getWritableDatabase(); 

被执行。

这条线上可能出现什么问题?

0 个答案:

没有答案