NullPointerException
Hello guys,
I get this error when I try this code out but I don't know what's causing it. If you know the answer, please let me know.
This is the JSP page:
<%@ page contentType="text/html"%>
<%@ page import="javax.xml.parsers.*"%>
<%@ page import="org.w3c.dom.*"%>
<%@ page import="dombean.*" %>
<jsp:useBean id="domparser" class="dombean.MyDOMParserBean" />
<%
Document doc = domparser.getDocument("c:/kris/stocks.xml");
NodeList nl = doc.getElementsByTagName("message");
%>
<html>
<body>
<%= nl.item(0).getFirstChild().getNodeValue() %>
</body>
</html>
This is the XML stocks.xml:
<?xml version="1.0" encoding="UTF-8"?>
<portfolio>
<stock>
<symbol>SUNW</symbol>
<name>Sun Microsystems</name>
<price>17.1</price>
</stock>
<stock>
<symbol>AOL</symbol>
<name>America Online</name>
<price>51.05</price>
</stock>
<stock>
<symbol>IBM</symbol>
<name>International Business Machines</name>
<price>116.10</price>
</stock>
<stock>
<symbol>MOT</symbol>
<name>MOTOROLA</name>
<price>15.20</price>
</stock>
</portfolio>
-
and this is the bean being used:
package dombean;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import java.io.*;
publicclass MyDOMParserBean
implements java.io.Serializable{
public MyDOMParserBean(){
}
publicstatic Document
getDocument(String file)throws Exception{
// Step 1: create a DocumentBuilderFactory
DocumentBuilderFactory dbf =
DocumentBuilderFactory.newInstance();
// Step 2: create a DocumentBuilder
DocumentBuilder db = dbf.newDocumentBuilder();
// Step 3: parse the input file to get a Document object
Document doc = db.parse(new File(file));
return doc;
}
}
Thanks for the help! Kris.

