Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Transformer.transform(), NullPointerException when writing attributes

843834Jul 18 2001 — edited Apr 5 2002
Hi!
I'm using xalan.jar. My program reads an xml file, parses it and then modify DOM structure (without any trouble).
Then I want to write the current updated DOM into the original xml file. But I get NullPointerException. The code is:
....................................
try{
// Crear TransformerFactory
TransformerFactory tf = TransformerFactory.newInstance();
// Crear Transformer
Transformer transformer = tf.newTransformer();

DOMSource origen = new DOMSource(doc);
StreamResult destino = new StreamResult(/*new File*/(fichero));
System.out.println(transformer.getOutputProperty(OutputKeys.VERSION));
transformer.transform(origen,destino);
} catch (TransformerConfigurationException tce) {
// Error generated by the parser
System.out.println ("\n** Transformer Factory error");
System.out.println(" " + tce.getMessage() );
// Use the contained exception, if any
Throwable x = tce;
if (tce.getException() != null)
x = tce.getException();
x.printStackTrace();
} catch (TransformerException te) {
// Error generated by the parser
System.out.println ("\n** Transformation error");
System.out.println(" " + te.getMessage() );
// Use the contained exception, if any
Throwable x = te;
if (te.getException() != null)
x = te.getException();
x.printStackTrace();
}
}
..........................................

and I get:

Exception in thread "main" java.lang.NullPointerException
at org.apache.xalan.serialize.SerializerToXML.writeAttrString(Serializer
ToXML.java:2001)
at org.apache.xalan.serialize.SerializerToXML.processAttribute(Serialize
rToXML.java:957)
at org.apache.xalan.serialize.SerializerToXML.startElement(SerializerToX
ML.java:829)
at org.apache.xalan.transformer.TransformerIdentityImpl.startElement(Tra
nsformerIdentityImpl.java:982)
at org.apache.xml.utils.TreeWalker.startNode(TreeWalker.java:284)
at org.apache.xml.utils.TreeWalker.traverse(TreeWalker.java:119)
at org.apache.xalan.transformer.TransformerIdentityImpl.transform(Transf
ormerIdentityImpl.java:320)
at Configuracion.guardarConfiguracion(Configuracion.java:161)
at Configuracion.main(Configuracion.java:235)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 3 2002
Added on Jul 18 2001
5 comments
2,433 views