java.lang.NullPointerException:尝试调用虚方法' int android.widget.ArrayAdapter.getCount()'在null对象引用上

时间:2015-04-24 00:40:06

标签: java android android-arrayadapter

我在logcat中有这个错误:

java.lang.NullPointerException: Attempt to invoke virtual method 'int android.widget.ArrayAdapter.getCount()' on a null object reference

当我尝试在适配器上执行for循环时。我认为它崩溃是因为适配器是在一个活动中声明的,但我需要做的循环是另一个。事实上,在我进行循环的活动中,我已经写了这个:

listView.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

               Cursor cursor = (Cursor) parent.getItemAtPosition(position);
               String fermata_partenza = cursor.getString(cursor.getColumnIndex(PreferitiDb.KEY_FERMATA_PARTENZA));
               String fermata_arrivo = cursor.getString(cursor.getColumnIndex(PreferitiDb.KEY_FERMATA_ARRIVO));
               Log.i("",fermata_partenza + " " + fermata_arrivo);


               for (int i = 0; i < SceltaFermateActivity.instance.adapter.getCount(); i++){
                   FermataComune obj = SceltaFermateActivity.instance.adapter.getItem(i);

                   if (obj.toString().contains(fermata_partenza)){
                       feramta_Partenze = (FermataComune) obj;
                   }
                   if (obj.toString().contains(fermata_arrivo)){
                       fermata_Arrivi = (FermataComune) obj;
                   }
               }

            }
        });

并且错误符合:SceltaFermateActivity.instance.adapter.getCount(); 有可能解决吗?

0 个答案:

没有答案