gpt4 book ai didi

jdom - 元素 "LevelRoot"无法添加为文档 : The Content already has an existing parent document 的根

转载 作者:行者123 更新时间:2023-12-04 14:03:41 25 4
gpt4 key购买 nike

我在使用 JDOM2 时遇到了一些麻烦。我想序列化我的树,然后我去添加第一个根元素,它说它已经添加到文档中,但它是我将它添加到的新文档。
代码:

SceneGraphNode root = SceneGraphManager.root;

Element root_element = root.xmlData;

CJournal.Journal(XMLAdapter.class, "Serializing root element: " + root_element.getName());

Document doc = new Document();

doc.addContent(root_element);

CJournal.Journal(XMLAdapter.class, "Root element serialized ");

for (SceneGraphNode child: root.children)
{
//save xml
CJournal.Journal(XMLAdapter.class, "Serializing element: " + child.xmlData.getName());
doc.addContent(child.xmlData);
RecursiveSerialize(child, doc);

还有我的堆栈跟踪:
187 In Class::class GameMap.XMLAdapter Journal Entry:Serializing root element: LevelRoot
Exception in thread "Thread-8" org.jdom2.IllegalAddException: The element "LevelRoot" could not be added as the root of the document: The Content already has an existing parent document
at org.jdom2.ContentList.checkPreConditions(ContentList.java:208)
at org.jdom2.ContentList.add(ContentList.java:244)
at org.jdom2.ContentList.add(ContentList.java:79)
at java.base/java.util.AbstractList.add(Unknown Source)
at org.jdom2.Document.addContent(Document.java:320)
at GameMap.XMLAdapter.Serialize(XMLAdapter.java:238)
at GameMap.CHotLoader.Serialize(CHotLoader.java:206)
at GameMap.CHotLoader.loadNMap(CHotLoader.java:132)
at GameMap.CHotLoader.loadMap(CHotLoader.java:115)
at GameMap.CHotLoader.HotLoad(CHotLoader.java:84)
at MainGame.Loop.run(Loop.java:29)

最佳答案

不应该是

root_element.addContent(child.xmlData);
像这样:
for (SceneGraphNode child: root.children)
{
//save xml
CJournal.Journal(XMLAdapter.class, "Serializing element: " + child.xmlData.getName());
root_element.addContent(child.xmlData);
RecursiveSerialize(child, doc);
}

关于jdom - 元素 "LevelRoot"无法添加为文档 : The Content already has an existing parent document 的根,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69224184/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com