当我运行这段代码时,我得到一个空指针异常
private void loadSpinnerData() {
// database handler
AttendAppDatasource db = new AttendAppDatasource(getApplicationContext());
// Spinner Drop down elements
List<String> clas = db.viewCol(AttendAppDbOpenHelper.COLUMN_CLASS);
Log.i("Select Class","List Assigned");
// Creating adapter for spinner
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, clas);
// Drop down layout style - list view with radio button
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// attaching data adapter to spinner
spinner.setAdapter(dataAdapter);
}
这是相关的日志输出
这是与列表对应的注销
答案 0 :(得分:1)
您的微调器设置为null。您需要从资源中获取
Spinner spinner = (Spinner) findViewById(R.id.'spinner_id_name');
然后你可以设置你的适配器:)