What I was doing therewas a simple attempt to use the transformer from the xml api to write an xml file:
Source source = new DOMSource (doc);
Result result = new StreamResult (new File (file));
Transformer transformer = TransformerFactory.newInstance ().newTransformer ();
transformer.transform (source, result);
Personally this is the worlds's most stupid error. Guess what the console gave as the eroor description : ERROR: '' "
Very helpful, isn’t it? What next? Well we'll proceed to the stack trace next:
Down somewhere in the jungle of exceptions you get Caused by: java.lang.NullPointerException
at com.sun.org.apache.xml.internal.serializer. ToUnknownStream.characters(ToUnknownStream.java:312)
the code there looks like this:
public void characters(String chars) throws SAXException
{
final int length = chars.length();
Now we finally see the part that threw the error. Well the char.kength() was zero because there was a null text node insertion beging tried. So now's the solution to this problem
1. Go through your source code
2. Find the text node that is null
3. Give it a String value
4. Recompile and run
OWLS ARE NOT ALWAYS WHAT THEY SEEM
Sir
ReplyDeleteAm new to servlets.I am gettin null pointer exception.pls do reply.. i need a clear explanation for null point exception.why is it occuring.pls do reply.
Dear Barathi,
ReplyDeleteThere is no specific criteria for the occurrence of a null pointer exception. It could be among a lot of reasons, few of them are listed below:
1. Referencing a variable that has been assigned null
2. Referencing an object before it has been instantiated
3. A null input case
4. Trying to instantiate a Bean that could only be interfaced with in case of EJBS
and many more...
hi iam getting same Error javax.xml.transform TransformerException: java.lang.NullPointerException because it ise getting a null value
ReplyDeleteat some textNode but all the text node value in my program are coming dynamically..i have handled all the nullPointers but still it is giving me the error please help if u can...
Since you are having dynamic text nodes, put a try block around the statements that could throw up the exception and then handle it in a catch block by allocating some value to the text node rather than retain its null value.
ReplyDeletei had put a try block around the statements around text node's for loop but the problem was the values were not null they were blank
ReplyDeleteso within try catch i put an if condition which was checking blank values it solved my problem...by the way thanks alot
Just had exactly the same problem, googled it and found your blog, solved it right away, thanks. Indeed, the "Error" error message is laughable, in a sad sad way..
ReplyDeleteHello,
ReplyDeleteLike Pedro, I had this problem, googled for it, and arrived here. My specificity is the error did not come directly from my code, but from SPRING WS. Spring WS triggered this error while attempting to log the an incoming soap message. Disabling logging for spring ws solved my problem.
log4j.logger.org.springframework.ws=INFO
log4j.logger.org.springframework.xml=INFO
Thank you very much, it save a lot of time!
ReplyDeletenice post buddy... solved my problem too...
ReplyDelete+1
ReplyDeleteThanks a lot !
Thank you. It's a shame that this isn't handled more elegantly...
ReplyDeleteThanks. You were my only good link off Google for this issue.
ReplyDeleteExactly the problem I had. Saved me a hours work for sure. Thanks! ^.^
ReplyDeleteThanks for your post! Helped me out a lot.
ReplyDeleteYou saved my life, this would have taken so long without this post. Thanks a lot.
ReplyDeleteDear Author.
ReplyDeleteI am facing same problem, But as my requirement is that I have to pass the text node null. Because I have to create null xml tag like
Please Let me know if any solution for it.
Thanks
Thanks a lot! it's been bugging my code for days!
ReplyDeleteHi,
ReplyDeleteWhat if the error about "namespace that has not been declared"?Error javax.xml.transform TransformerException: java.lang.RuntimeException