I am having a weird error, I am using a variable that I create but then I makes a Null Pointer Exception Error. Here is my code :
public class ReadXMLFile {
// Initialize logger
private static Logger log = Logger.getLogger(ReadXMLFile.class);
public Document getXMLDocument() {
Document doc = null;
File configXmlFile = new File("");
try {
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory
.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
System.out.println(LanguageHandler.source); //null
configXmlFile = LanguageHandler.source;
System.out.println(LanguageHandler.source); //null
System.out.println("conf : " + configXmlFile.isFile()); //Null pointer exception
doc = docBuilder.parse(configXmlFile);
} catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage(), e);
}
return doc;
}
}
And here is the error :
java.lang.NullPointerException
at in.raster.oviyam.util.ReadXMLFile.getXMLDocument(ReadXMLFile.java:85)
at in.raster.oviyam.util.ReadXMLFile.getElementValues(ReadXMLFile.java:99)
at in.raster.oviyam.servlet.DicomNodes.doGet(DicomNodes.java:90)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Line 85 of the ReadXMLFile class is my System.out.println("conf : " + configXmlFile.isFile());
I don't understand why I am having this error, it should just return false.
Thanks in advance for help !!
V.
null pointer exceptionmeans you're trying to access something that doesn't exist. That very likely means thatconfigXmlFilewasn't created / instantiated properly. Check that first.configXmlFileisnullas you have suggested through the program output, how are you expecting your program to skip aNullPointerException?