-1

i'm trying to remove all elements from mapSet but i getting ConcurrentModificationException so i have some checked boxes and their vlues is in mapset but i want to when press submit button it removes all of mapset values .

my code :

 sumbit.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            if(checkNoAttndance.isChecked()==true){

                  for (Map.Entry<Integer, Integer> mapEntry : checkBoxState
                          .entrySet()){

                          checkBoxState.remove(mapEntry.getKey());

                          }

            }
            else if (checkBoxState.isEmpty()) {

                Toast.makeText(activity, "الرجاء اختيار اسماء الطلبة الغائبون ",
                        Toast.LENGTH_SHORT).show();

            }

            else {

                ProgressDialog progressDialog = new ProgressDialog(activity);
                progressDialog
                        .setMessage("جاري ارسال البيانات ، الرجاء الانتظار");
                progressDialog.show();

                SendListSync asynTask = new SendListSync(context, activity,
                        checkBoxState, progressDialog);
                asynTask.execute();

            }

        }
    });
user3142633
  • 21
  • 1
  • 3
  • 1
    Look at all those related questions... – Sotirios Delimanolis Dec 28 '13 at 19:47
  • 1
    Possible duplicate of [Iterating through a Collection, avoiding ConcurrentModificationException when removing in loop](http://stackoverflow.com/questions/223918/iterating-through-a-collection-avoiding-concurrentmodificationexception-when-re) – Raedwald Mar 28 '16 at 14:43

1 Answers1

1

replace

if(checkNoAttndance.isChecked()==true){
      for (Map.Entry<Integer, Integer> mapEntry : checkBoxState.entrySet()){
             checkBoxState.remove(mapEntry.getKey());
      }
}

with

if(checkNoAttndance.isChecked()){
      checkBoxState.clear();
}
Gopal Gopi
  • 11,101
  • 1
  • 30
  • 43