如何解决此错误NullPointerException Spinner-ArrayAdapter

时间:2013-12-25 23:51:52

标签: java android

当我尝试将适配器设置为微调器时,我得到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) {
        }

    });

0 个答案:

没有答案