当执行“this.getReadableDatabase”时,跳过以下代码并抛出异常

时间:2015-07-20 11:15:29

标签: android sqlite

 public List<MedicalCase> getPersonalCase(int personid) {

    Cursor c = null;
    MedicalCase mMedicalCase = new MedicalCase();
    List<MedicalCase> myList = new ArrayList<MedicalCase>();

    try {

        synchronized (DBLOCK) {

            SQLiteDatabase db = this.getReadableDatabase();
            String str_personid = String.valueOf(personid);
            c = db.query(true, TABLE_Case, new String[]{MedicalCase_CaseId, MedicalCase_CaseCoverImageFileName,
                            MedicalCase_CaseColor, MedicalCase_CaseName,
                            MedicalCase_StartDate, MedicalCase_EndDate},
                    Person_PersonId + " = ?", new String[]{str_personid}, null, null, null, null);

            if (c != null && c.moveToFirst()) {
                do {
                    mMedicalCase.setCaseId(c.getColumnIndex(MedicalCase_CaseId));
                    mMedicalCase.setCaseCoverImageFileName(c.getString(c.getColumnIndex(MedicalCase_CaseCoverImageFileName)));
                    mMedicalCase.setCaseColor(c.getString(c.getColumnIndex(MedicalCase_CaseColor)));
                    mMedicalCase.setCaseName(c.getString(c.getColumnIndex(MedicalCase_CaseName)));
                    mMedicalCase.setStartDate(c.getLong(c.getColumnIndex(MedicalCase_StartDate)));
                    mMedicalCase.setEndDate(c.getLong(c.getColumnIndex(MedicalCase_EndDate)));
                    myList.add(mMedicalCase);
                } while (c.moveToNext());
            }
        }
        c.close();
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }

    return myList;
}

这是我的代码,当执行this.getReadableDatabase时,跳过以下代码并抛出异常,但不转到String str_personid = String.valueOf(personid);

我认为SQLiteDatabase db = this.getReadableDatabase()可能是NullPointer,但我不确定它是否错误。

0 个答案:

没有答案