我试图从这里贾乌德我的XML文件中获取的所有作者是XML代码空指针在Java中
<?xml version="1.0"?>
<map>
<authors>
<author>testasdas</author>
<author>Test</author>
</authors>
</map>
下面是我在Java中使用
代码public static List<String> getAuthors(Document doc) throws Exception {
List<String> authors = new ArrayList<String>();
Element ed = doc.getDocumentElement();
if (notExists(ed, "authors")) throw new Exception("No authors found");
Node coreNode = doc.getElementsByTagName("authors").item(0);
if (coreNode.getNodeType() == Node.ELEMENT_NODE) {
Element coreElement = (Element) coreNode;
NodeList cores = coreElement.getChildNodes();
for (int i = 0; i < cores.getLength(); i++) {
Node node = cores.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element e = (Element) node;
String author = e.getElementsByTagName("author").item(i).getTextContent();
Bukkit.getServer().broadcastMessage("here");
authors.add(author);
}
}
}
return authors;
}
我在尝试运行代码时遇到了java.lang.NullPointerException
错误,但我不知道为什么。
09.04 17点05分24秒[服务器]重症在com.dcsoft.arenagames.map.XMLHandler.getMapData(XMLHandler.java:42)
09.04 17点05分24秒[服务器]重症在COM。 dcsoft.arenagames.map.XMLHandler.getAuthors(XMLHandler.java:73)
09.04 17时05分24秒[服务器]重症显示java.lang.NullPointerException
完整的堆栈跟踪在哪里? – BobTheBuilder 2013-04-09 16:17:11
'尝试.. catch' - >堆栈跟踪? – 2013-04-09 16:17:12
这是XMLHandler.java的第73行吗? – 2013-04-09 16:20:52