i get this exception when I try to generate xml file

Discussion in 'Java' started by ab2305@gmail.com, Feb 5, 2006.

  1. Guest

    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)
     
    , Feb 5, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bienwell
    Replies:
    4
    Views:
    3,861
    bienwell
    May 27, 2005
  2. John Salerno
    Replies:
    20
    Views:
    861
    John Salerno
    Aug 11, 2006
  3. Fabio Z Tessitore

    who is simpler? try/except/else or try/except

    Fabio Z Tessitore, Aug 12, 2007, in forum: Python
    Replies:
    5
    Views:
    379
  4. =?Utf-8?B?QUo=?=

    When to TRY and not to TRY

    =?Utf-8?B?QUo=?=, Oct 16, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    330
    sloan
    Oct 17, 2007
  5. Jake Barnes
    Replies:
    2
    Views:
    129
    Jake Barnes
    Apr 7, 2006
Loading...

Share This Page