lundi 20 juillet 2015

when Perform to "this.getReadableDatabase",skip the following code and throws Exception

 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 is my code ,when Perform to this.getReadableDatabase,skip the following code and throws Exception,but not go to String str_personid = String.valueOf(personid);

I think that it is maybe the SQLiteDatabase db = this.getReadableDatabase() is NullPointer,but i dont sure if it is wrong.

Aucun commentaire:

Enregistrer un commentaire