当我尝试将适配器设置为微调器时,我得到NullPointerException
,这是代码中的错误部分,请感谢您的帮助,谢谢。
mDeptDom
是一个对象列表,其中包含String和List<String>
作为值,每当我将ArrayAdapter
设置为另一个微调器时,我就会得到着名的NullPointerException
mDeptDom = deptDomDao.findAll();
List<String> nomDept = new ArrayList<String>();
for (int i = 0; i < mDeptDom.size(); i++) {
nomDept.add(mDeptDom.get(i).getNom());
}
ArrayAdapter<String> deptAdapter = new ArrayAdapter<String> (this,android.R.layout.simple_spinner_item, nomDept);
deptAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spDepartementDom.setAdapter(deptAdapter);
spDepartementExp.setAdapter(deptAdapter);
spDepartementDom.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
dept = arg0.getSelectedItem().toString();
for(int i=0;i<mDeptDom.size();i++){
if(mDeptDom.get(i).getNom().equalsIgnoreCase(dept)){
mVilleC= mDeptDom.get(i).getListVille();
break;
}
}
List<String> mNomVilleC=new ArrayList<String>();
for(int i=0;i<mVilleC.size();i++){
mNomVilleC.add(mVilleC.get(i).getNomV());
}
// System.out.println(" BoooM " + mNomVilleC);
/*ArrayAdapter<String> nomVilleAdapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_spinner_item, mNomVilleC);
nomVilleAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spVilleDom.setAdapter(nomVilleAdapter); */
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});