  | |  | Serialization giving probem with HashMap | Serialization giving probem with HashMap 2003-05-02 - By peter peter
Hi, I am creating a new document and could serialize it without fail. But if I add the created document to the HashMap. and then get the document from hashMap and try to serialize, OutputFormat throws NullPointerException, Here's the exception message--- /*java.lang.NullPointerException at org.apache.xml.serialize.OutputFormat.whichMethod(Unknown Source) at org.apache.xml.serialize.OutputFormat.<init>(Unknown Source)*/ Here 's the code I am using---> HashMap documentsMap = new HashMap(); Document doc= new DocumentImpl(); Element root = doc.createElement("person"); // Create Root Element Element item = doc.createElement("name"); // Create element item.appendChild( doc.createTextNode("Jeff") ); root.appendChild( item ); // Attach another Element - doc.appendChild( root ); // Add Root to Document//add to the HashMap.... documentsMap.put("node1",doc ); try { Iterator iterator = documentsMap.entrySet().iterator(); while (iterator.hasNext() ) { Object key = iterator.next(); doc= (Document)taxonomyNodesMap.get(key); OutputFormat format = new OutputFormat( doc ); //Serialize DOM StringWriter stringOut = new StringWriter(); //Writer will be a XMLSerializer serial = new XMLSerializer( stringOut, format ); serial.asDOMSerializer(); // As a DOM Serializer serial.serialize( doc.getDocumentElement()); } }catch...... Any help will be greatly appreciated.. Regards,Peter
--------------------------------- Do you Yahoo!? The New Yahoo! Search - Faster. Easier. Bingo. <DIV>Hi,</DIV> <DIV> I am creating a new document and could serialize it without fail.</DIV> <DIV> </DIV> <DIV> But if I add the created document to the HashMap. and then get the document from hashMap and try to serialize,  ;OutputFormat throws NullPointerException,</DIV> <DIV> </DIV> <DIV>Here's the exception message---</DIV> <DIV> </DIV> <DIV>/*</DIV> <DIV>java.lang.NullPointerException<BR> at org.apache.xml.serialize.OutputFormat.whichMethod(Unknown Source)<BR> at org.apache.xml.serialize .OutputFormat.<init>(Unknown Source)*/</DIV> <DIV> </DIV> <DIV>Here's the code I am using---></DIV> <DIV> </DIV> <DIV> HashMap documentsMap = new HashMap();<BR> Document doc= new DocumentImpl();<BR> Element root = doc.createElement("person");   ; // Create Root Element<BR> Element item = doc.createElement( "name"); // Create element<BR> item .appendChild( doc.createTextNode("Jeff") ); <BR> root.appendChild( item ); // Attach another Element - doc.appendChild( root );   ; // Add Root to Document</DIV> <DIV>//add to the HashMap....<BR>documentsMap.put("node1",doc );<BR>   ;try<BR> {<BR> Iterator iterator = documentsMap .entrySet().iterator();<BR> while (iterator.hasNext() )<BR> {<BR> Object key = iterator.next ();<BR> doc= (Document)taxonomyNodesMap.get(key); <BR> OutputFormat format = new OutputFormat( doc ); //Serialize DOM<BR>   ;StringWriter stringOut = new StringWriter();   ; //Writer will be a </DIV> <DIV> XMLSerializer serial = new XMLSerializer( stringOut, format );<BR> serial .asDOMSerializer(); // As a DOM Serializer<BR>   ;serial.serialize( doc.getDocumentElement());<BR> }<BR> }catch......</DIV> <DIV> </DIV> <DIV>Any help will be greatly appreciated..</DIV> <DIV> </DIV> <DIV>Regards,</DIV> <DIV>Peter</DIV><BR><BR><p><hr SIZE=1> Do you Yahoo!?<br> <a href="http://us.rd.yahoo.com/search/mailsig/*http://search.yahoo.com">The New Yahoo! Search</a> - Faster. Easier. Bingo.
|
|
 |