Null pointer when reading XML in Java

kasperandsky

New Member
I am trying to get the all the authors from my xml file in jave here is the xml code\[code\]<?xml version="1.0"?><map><authors> <author>testasdas</author> <author>Test</author></authors></map>\[/code\]Here is the code I'm using in Java\[code\]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;}\[/code\]I am getting a \[code\]java.lang.NullPointerException\[/code\] error when I try run the code but I'm not sure why.\[quote\] 09.04 17:05:24 [Server] SEVERE at com.dcsoft.arenagames.map.XMLHandler.getMapData(XMLHandler.java:42)
09.04 17:05:24 [Server] SEVERE at com.dcsoft.arenagames.map.XMLHandler.getAuthors(XMLHandler.java:73)
09.04 17:05:24 [Server] SEVERE java.lang.NullPointerException\[/quote\]
 
Top