ConcurrentModificationException的

时间:2013-12-28 19:46:51

标签: java android

我正在尝试从mapSet中删除所有元素,但我得到了ConcurrentModificationException,所以我有一些复选框,他们的vlues在mapset中,但我想按下提交按钮时删除所有mapset值。

我的代码:

 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();

            }

        }
    });

1 个答案:

答案 0 :(得分:1)

替换

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

if(checkNoAttndance.isChecked()){
      checkBoxState.clear();
}
相关问题