Code that throws the NullPointer 2003-03-16 - By Kirsten Barber
Thanks Panos for the recommendation.
I have a Java class that manipulates the XMLDocument that I am using in a series of Java servlets. Below is a part of the code, specifically the method that is throwing the nullpointer exception. I have taken out some comments, but I have already verified that the variable "mainDoc" is not null when I am calling the .normalize() method. It looks to me like normalize is calling several functions and one of them is throwing the null pointer exception. So logically, the error would have to be in the Document, but my document parses using both XSelerator and XMLSpy.
Again, thanks for any advice!
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilder; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.dom.DOMSource;
public class XMLManager { Document mainDoc = null;
public void storeXML() throws Exception { mainDoc.normalize(); //THIS IS THE LINE WHERE THE NULL POINTER EXCEPTION IS THROWN
TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = tf.newTransformer(); DOMSource ds = new DOMSource(mainDoc.getDocumentElement());
File newXML = new File(path + filename); FileOutputStream os = new FileOutputStream(newXML); StreamResult sr = new StreamResult(os);
t.transform(ds, sr); os.close();
} }
--------------------------------------------------------------------- To unsubscribe, e-mail: xerces-j-user-unsubscribe@(protected) For additional commands, e-mail: xerces-j-user-help@(protected)
|
|