i get this exception when I try to generate xml file

A

ab2305

this is my method (followed by exception):

public void generateXML(String fileName, BookInfoBean bookInfo){
try{
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance( );

DocumentBuilder parser = factory.newDocumentBuilder( );
Document doc = parser.newDocument();
Node root = doc.createElement(AmazonConstants.BOOKINFO);
doc.appendChild(root);

Node asin = doc.createElement(AmazonConstants.ASIN);
root.appendChild(asin);
asin.appendChild(doc.createTextNode(bookInfo.getAsin()));

Node title= doc.createElement(AmazonConstants.TITLE);
root.appendChild(title);
title.appendChild(doc.createTextNode(bookInfo.getTitle()));

Node rank= doc.createElement(AmazonConstants.SALESRANK);
root.appendChild(rank);

rank.appendChild(doc.createTextNode(bookInfo.getSalesRank()));

//create/save the actual file.
final Transformer
transformer=TransformerFactory.newInstance().newTransformer();

final DocumentType doctype = doc.getDoctype();
if (doctype != null)
{

transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC,
doctype.getPublicId());

transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,doctype.getSystemId());
}


transformer.transform(new DOMSource(doc),new
StreamResult(new FileOutputStream(fileName)));


} catch (Exception ex) {
System.err.println(ex.getClass( ));
System.err.println(ex.getMessage( ));
ex.printStackTrace();
}


---------------------exception
ERROR: ''
class javax.xml.transform.TransformerException
java.lang.NullPointerException
javax.xml.transform.TransformerException:
java.lang.NullPointerException
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown
Source)
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown
Source)
at
com.touchgraph.amazoncache.io.CacheStore.generateXML(CacheStore.java:148)
at
com.touchgraph.amazoncache.io.AmazonCacheEngine.main(AmazonCacheEngine.java:18)
Caused by: java.lang.NullPointerException
at
com.sun.org.apache.xml.internal.serializer.ToUnknownStream.characters(Unknown
Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown
Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown
Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown
Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown
Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown
Source)
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(Unknown
Source)
... 4 more
---------
java.lang.NullPointerException
at
com.sun.org.apache.xml.internal.serializer.ToUnknownStream.characters(Unknown
Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown
Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown
Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown
Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown
Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.DOM2TO.parse(Unknown
Source)
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(Unknown
Source)
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown
Source)
at
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown
Source)
at
com.touchgraph.amazoncache.io.CacheStore.generateXML(CacheStore.java:148)
at
com.touchgraph.amazoncache.io.AmazonCacheEngine.main(AmazonCacheEngine.java:18)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,739
Latest member
Clint8040

Latest Threads

Top