You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Kirsten Barber <ki...@san.rr.com> on 2003/03/16 22:48:38 UTC

Code that throws the NullPointer

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@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Code that throws the NullPointer

Posted by Elena Litani <el...@ca.ibm.com>.
Kirsten Barber wrote:
> 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.

Xerces does load the document you mention without any error. I actually
modified dom.Writer sample to add normalize() call on the document after
it is parsed (line 516) and there is no NPE.

Where do you get your document?
How do you load it? What features you turn on during loading?

Thanks,
-- 
Elena Litani / IBM Toronto

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Code that throws the NullPointer

Posted by Panos Konstantinidis <gi...@yahoo.com>.
> 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

  How did you do this? Have you put a
System.out.println statement right before you call the
normalize() method and it was not null? What is the
output of this:

     public void storeXML() throws Exception
     {
        System.out.println("mainDoc: " + mainDoc);
        mainDoc.normalize();   //THIS IS THE LINE
 WHERE THE NULL POINTER 
 EXCEPTION IS THROWN
        ...
     }
  
  And most importantly where do you initialize your
"mainDoc" variable?

> 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 

  It could be yes. Do you get any other error messages
on the console/log files? Have you tried using a
debugger and step through each statement?


__________________________________________________
Do you Yahoo!?
Yahoo! Web Hosting - establish your business online
http://webhosting.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org