Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to overcome the Concurrent Modification Exception

843834Nov 11 2008 — edited Nov 11 2008
Hi friends,

I have done to delete the Element in xml using java.If i run the program it deleted the element name like (param).
But it throw ConcurrentModification Exception
Please help me

My code is

import java.util.*;import java.io.*; import org.jdom.*;import org.jdom.output.*; import org.jdom.input.*; import org.jdom.*;
public class Remove1 {
public void remove1()throws JDOMException, IOException{
File file = new File("c://system.xml");
SAXBuilder builder = new SAXBuilder();
Document doc =builder.build(file);
Element root = doc.getRootElement();
Iterator userListe = root.getChildren("param").iterator();//get the element value
while (userListe.hasNext()) {
Element eUser = (Element) userListe.next();
if(eUser.getAttribute("name").getValue().equals("ui_add")){//get the attribute and compare with value
root.removeContent(eUser);
try {
FileOutputStream fos = new FileOutputStream(file);
XMLOutputter out = new XMLOutputter();
out.output(doc, fos);
} catch (Exception e) {
System.out.println("ahi");
}
}
}
}
}
XML Code:

<?xml version="1.0" encoding="UTF-8"?>
<system version="3.0">
<param name="app">portal</param>
<param name="ui_add">
</CC_HEADER_MENU>
</param>
<param name="ui_hide">
<CC_HEADER_MENU_logoff/>
</param>
</system>

Exception is :
500 Internal Server Error
java.util.ConcurrentModificationException at org.jdom.ContentList$FilterListIterator.checkConcurrentModification(ContentList.java:940) at org.jdom.ContentList$FilterListIterator.nextIndex(ContentList.java:829) at org.jdom.ContentList$FilterListIterator.hasNext(ContentList.java:785) at
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 9 2008
Added on Nov 11 2008
1 comment
454 views