关于 Finalizing a Cursor that has not been deactivated or closed错误

使用Sqlite时,有时有下面的异常:Finalizing a Cursor that has not been deactivated or closed。 主要原因是游标cursor使用后没有关闭
public List getAllSubject(Context context) {
		List Subjects = new ArrayList();
		// sqLiteOpenHelper = new HomeworkSQLiteOpenHelper(context);
		// database = sqLiteOpenHelper.getWritableDatabase();
		database = HomeworkSQLiteOpenHelper.getInstance(context)
				.getWritableDatabase();
		String sql = "select * from " + DbData.SUBJECT_DB_TABLE_NAME;
		Cursor cursor = database.rawQuery(sql, null);
		while (cursor.moveToNext()) {
			Subject Subject = new Subject();
			Subject.setId(cursor.getInt(0));
			Subject.setName(cursor.getString(1));
			Subjects.add(Subject);
		}
	cursor.close();
		closeAll();
		return Subjects;
	}

你可能感兴趣的:(android学习)