我在下面一行发生错误。 我正在做添加到jsonarray的过程。 请帮帮我。我该如何解决这个错误java.util.ConcurrentModificationException
jsonArr=new JSONArray();
if(req.getSession().getAttribute("userses")!=null){
String name=(req.getParameter("name")==null?"":to_EnglishName(req.getParameter("name").toUpperCase()));
if(!name.equals("")){
for(Book c:GlobalObjects.bookList){
if(c.getBookName().startsWith(name)){
jsonObjec=new JSONObject();
jsonObjec.put("label",c.getBookName());
jsonObjec.put("value", c.getId());
jsonArr.add(jsonObjec);//java.util.ConcurrentModificationException
}
}
}
}
jsonArr.write(res.getWriter());
你尝试过这么远吗?你读过ConcurrentModificationException的JavaDoc吗? – 2012-07-10 06:33:54
你是否遗漏了一些代码,你实际上是在迭代你添加项目的JSONArray? – Confusion 2012-07-10 06:42:30