xiaoshiniudao
2011-05-02 11:05
浏览 1.1k
已采纳

List操作错误Exception in thread "main" java.lang.IllegalStateException

Iterator<Teacher> iter = teacherList.iterator();
while(iter.hasNext()){
    Teacher teacher =iter.next();
    //①查找老师的最大上限值,如果该老师已经达到上限了,则将该老师从List中拿出,不予安排
    if(teacher.getMaxnum()<=teacher.getRealnum()){
    iter.remove();
    teacherList.remove(teacher);
    }
    //②找到该考试的时间点,如果该考试桶中存在与该老师的ID则将该老师摘除,不予考虑.
    if(examBarrelDao.isRelated(exam,teacher)){
    iter.remove();
    teacherList.remove(teacher);
    }
    }
    //③按照监考上限减去监考下限差额最大的顺序排列,取该老师序列的第一个为最优老师。
    for(int i=0;i<teacherList.size()-1;i++){
        for (int j=i+1;j<teacherList.size();j++){
        Teacher teacher = new Teacher();
        if(teacherList.get(i).getMaxnum()-teacherList.get(i).getRealnum()
                                <teacherList.get(j).getMaxnum()-teacherList.get(j).getRealnum()){
                teacher =teacherList.get(i);
                teacherList.set(i, teacherList.get(j));
                teacherList.set(j, teacher);
                }
            }

我将得到的List判断以后,remove了其中的不符合条件的teacher,然后将List中剩余的teacher重新按照大小进行了一次排序,但是有时报 Exception in thread "main" java.lang.IllegalStateException
at java.util.AbstractList$Itr.remove(Unknown Source)
at com.sdjzglxy.jwMis.help.ConditionalJudge.listTeacher(ConditionalJudge.java:229)
at com.sdjzglxy.jwMis.help.ConditionalJudge.teacherChoiceForSecond(ConditionalJudge.java:162)
at com.sdjzglxy.jwMis.action.ArrayExam.arraySecondTeacher(ArrayExam.java:132)
at com.sdjzglxy.jwMis.action.ArrayExam.main(ArrayExam.java:159)
有时对有时错,我想问一下,该如何解决这个问题……

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • tianzizhi3 2011-05-02 19:41
    已采纳

    iter.remove();
    teacherList.remove(teacher);

    你删除两次,只用iter.remove(); 就行了

    打赏 评论

相关推荐 更多相似问题