I am new and very beginner to Android development. I am trying to get the textView from ChildList (expandableListView) where checkbox is selected but I am getting null reference error on running the code. Can you please help. Below is the error
Attempt to invoke virtual method 'java.lang.String java.util.ArrayList.toString()' on a null object reference
below is the Extract of code.
I am calling this in the main activity to get the arraylist of text for which checkbox is selected.
public String getSelectedItems(int mGroupPosition)
{
boolean getChecked[] = mChildCheckStates.get(mGroupPosition);
ArrayList<String> selectedList = null;
if(getChecked != null) {
for (int j = 0; j < getChecked.length; ++j) {
if (getChecked[j] == true) {
String selectedItem = mListDataChild.get(j).toString();
selectedList.add(selectedItem);
}
}
}
return selectedList.toString();
}
Code in Main Activity
selectedButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ArrayList<String> selectedItemsList = null;
for (int mGroupPosition = 0; mGroupPosition<listAdapter.getGroupCount(); mGroupPosition++){
selectedItemsList.add(listAdapter.getSelectedItems(mGroupPosition));
}
Log.i("selected Items",selectedItemsList.toString());
}
});
Aucun commentaire:
Enregistrer un commentaire