I have an activity that has a checkbox, then under it is a list of contacts populating my listview with checkboxes for each contact. I have two major problems stemming from my question.
chkbox_foo is outside of the listview, and chk_bar is inside. chk_foo works, but anything related to chk_bar after being initialized causes the app to crash. Also, if I create a setOnCheckedChangeListener for chkbox_bar, that will cause the app to crash also. Does anyone know why this is happening and how I can fix this?
btn_foo = (Button) findViewById(R.id.btn_foo); barList = (ListView) findViewById(R.id.lv_barList); chk_foo = (CheckBox) findViewById(R.id.cb_foo); chk_bar = (CheckBox) findViewById(R.id.cb_bar); // set checkboxes state as false at beginning chkboxAllVisible = false; chkboxSingleChk = false; chk_foo.setChecked(chkboxAllVisible); chk_bar.setChecked(chkboxChk); <---App crashes here // Outside of listview checkbox chk_foo.setOnCheckedChangeListener(new OnCheckedChangeListener(){ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { Log.d(TAG, "checkbox changed " + isChecked); if(isChecked){ chkboxAllVisible = true; chk_bar.setChecked(isChecked); <---app crashes here too } } }); // Outside of listview checkbox chk_bar.setOnCheckedChangeListen... <---app crashes here also