다음은 클래스 룸 출석을 표시하기 위해 사용자 지정 어댑터를 호출하는 간단한 List 활동입니다. 여기에 오기 위해 클릭 한 교실 rowid를 사용하여 데이터를 설정 한 다음 내 DB에 쿼리하여 클래스의 모든 학생을 얻습니다. 나는 학생 이름과 함께 체크 박스 목록이 있기 때문에 맞춤 어댑터를 사용합니다. 상관없이 내 어댑터를 사용하거나 단순히 simplecursoradapter (그리고 내 체크 박스 기능을 잃게) 대신 null 포인터 예외를 얻을 출구에서 대체하십시오. 이것은 "완료"버튼을 클릭하거나 뒤로 화살표를 클릭 하든지 발생합니다. 나는 아무것도 볼 수없는 것 같습니다. 너는 할수 있니?누구나 출구에서 null 포인터 예외가 발생하는 이유를 볼 수 있습니다.
public class ShowStudentAttendance extends ListActivity {
private gradeBookDbAdapter mDbHelper;
private Long mRowId;
private TextView mNameText;
private String classname;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Cursor stud;
mDbHelper = new gradeBookDbAdapter(this);
mDbHelper.open();
mRowId = (savedInstanceState == null) ? null
: (Long) savedInstanceState
.getSerializable(gradeBookDbAdapter.KEY_ROWID);
if (mRowId == null) {
Bundle extras = getIntent().getExtras();
mRowId = extras != null ? extras
.getLong(gradeBookDbAdapter.KEY_ROWID) : null;
}
if (mRowId != null) {
stud = mDbHelper.fetchClass(mRowId);
startManagingCursor(stud);
classname = stud.getString(
stud.getColumnIndexOrThrow(gradeBookDbAdapter.KEY_CLASSNAME));
String title = "Attendance for " + classname;
setTitle(title);
}
stud = mDbHelper.fetchAllStudentsClass(mRowId);
startManagingCursor(stud);
setContentView(R.layout.attendance_list);
Button doneButton = (Button) findViewById(R.id.Done);
doneButton.setOnClickListener(mAttendanceActivity);
// Create an array to specify the fields we want to display in the list (only name)
String[] from = new String[]{gradeBookDbAdapter.KEY_NAME,
gradeBookDbAdapter.KEY_ROWID};
// and an array of the fields we want to bind those fields to (in this case just text1)
int[] to = new int[]{R.id.stuname};
// Now create a simple cursor adapter and set it to display
MyDataAdapter studs =
new MyDataAdapter(this, R.layout.show_attendance, stud, from, to);
setListAdapter(studs);
}
private OnClickListener mAttendanceActivity = new OnClickListener() {
public void onClick(View v) {
setResult(RESULT_OK);
finish();
}
};
}
스택 트레이스 추가 – mibollma