我在下面一行發生錯誤。 我正在做添加到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