My method getHomework should read a row from table, create object Homework, fill the object with data and return it.
my code:
public Homework getHomework(long id){
SQLiteDatabase db = this.getReadableDatabase();
String[] selectionArgs = { String.valueOf(id) };
Cursor cursor = db.query(TABLE_HOMEWORK, COLUMNS, KEY_ID + "= ?", selectionArgs, null, null, KEY_ID + " DESC");
Homework homework = new Homework();
homework.setId(Long.parseLong(cursor.getString(0)));
homework.setDate(cursor.getString(1));
homework.setNotification_time(cursor.getString(2));
homework.setSubject(cursor.getString(3));
homework.setContent(cursor.getString(4));
homework.setDescription(cursor.getString(5));
db.close();
// 5. return homework
return homework;
}
But my app always crashes in the line Cursor cursor... I also tried rawQuery(query, null) method instead of query method, but it didn't help.
Aucun commentaire:
Enregistrer un commentaire