- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个包含列表的 XML 文件,其中每个元素只有一个属性,我试图删除一个特定的元素,但它不起作用。我的删除 Java 代码是:
SAXBuilder builder = new SAXBuilder();
Document readDoc;
try {
readDoc = builder.build(new File(INACTIVE_FILE));
List<Element> inactiveDocList = readDoc.getRootElement().getChild("inactiveDoctorList").getChildren();
for(Element e: inactiveDocList){
if(e.getAttributeValue("inactiveDoctorID").equals("1")){
e.removeContent();
}
}
XMLOutputter xmlOutput = new XMLOutputter(Format.getPrettyFormat());
xmlOutput.output(readDoc.getRootElement(), new FileOutputStream(new File(INACTIVE_FILE)));
}
catch (JDOMException | IOException e) {
e.printStackTrace();
}
我的 XML 是:
<root>
<inactiveDoctorList>
<doctor inactiveDoctorID="1" />
<doctor inactiveDoctorID="2" />
<doctor inactiveDoctorID="4" />
<doctor inactiveDoctorID="16" />
<doctor inactiveDoctorID="3" />
<doctor inactiveDoctorID="9" />
<doctor inactiveDoctorID="13" />
<doctor inactiveDoctorID="14" />
<doctor inactiveDoctorID="11" />
<doctor inactiveDoctorID="6" />
</inactiveDoctorList>
</root>
当我执行 e.removeContent() 或 e.removeChild("doctor") 时没有任何反应,而当我尝试 e.detach() 时出现此错误:
Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException: The ContentList supporting the FilterList this iterator is processing has been modified by something other than this Iterator.
at org.jdom2.ContentList$FilterListIterator.checkConcurrent(ContentList.java:1309)
at org.jdom2.ContentList$FilterListIterator.next(ContentList.java:1357)
at org.jdom2.ContentList$FilterListIterator.next(ContentList.java:1260)
at edu.miami.cis324.swing.jfarache.RestorePatDoc.reactivate(RestorePatDoc.java:61)
at edu.miami.cis324.swing.jfarache.MainFrame$13.actionPerformed(MainFrame.java:741)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
有人知道这是怎么回事吗?
提前致谢!
最佳答案
您不能从 for-each 循环内部更改基础集合,您需要一个 while 循环或一个实际的迭代器。
它不适用于 for-each 循环,因为删除(或添加)元素意味着循环将不再知道下一个要显示的元素。我不知道 removeContent() 或 removeChild() 但这就是 detach() 抛出该异常的原因。
关于java - 为什么 removeContent()、removeChild() 和 detach() 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23302037/
今天有小伙伴给我留言问到,try{...}catch(){...}是什么意思?它用来干什么? 简单的说 他们是用来捕获异常的 下面我们通过一个例子来详细讲解下
我正在努力提高网站的可访问性,但我不知道如何在页脚中标记社交媒体链接列表。这些链接指向我在 facecook、twitter 等上的帐户。我不想用 role="navigation" 标记这些链接,因
说现在是 6 点,我有一个 Timer 并在 10 点安排了一个 TimerTask。之后,System DateTime 被其他服务(例如 ntp)调整为 9 点钟。我仍然希望我的 TimerTas
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我就废话不多说了,大家还是直接看代码吧~ ? 1
Maven系列1 1.什么是Maven? Maven是一个项目管理工具,它包含了一个对象模型。一组标准集合,一个依赖管理系统。和用来运行定义在生命周期阶段中插件目标和逻辑。 核心功能 Mav
我是一名优秀的程序员,十分优秀!