Details
Description
My Code is throwing an Exception while Converting XML file to Java Object
The Exception is
Exception in thread "main" null
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:669)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:563)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:746)
at com.thirdpillar.transformxml.BasicTransformer.main(BasicTransformer.java:28)
Caused by: java.lang.NullPointerException
at org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.java:757)
at org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.java:1121)
at org.apache.xerces.parsers.SAXParser.endElement(SAXParser.java:1403)
at org.apache.xerces.validators.common.XMLValidator.callEndElement(XMLValidator.java:1436)
at org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XMLDocumentScanner.java:1205)
at org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:381)
at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1035)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:655)
... 3 more
Caused by: java.lang.NullPointerException
at org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.java:757)
at org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.java:1121)
at org.apache.xerces.parsers.SAXParser.endElement(SAXParser.java:1403)
at org.apache.xerces.validators.common.XMLValidator.callEndElement(XMLValidator.java:1436)
at org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XMLDocumentScanner.java:1205)
at org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:381)
at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1035)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:655)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:563)
at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:746)
at com.thirdpillar.transformxml.BasicTransformer.main(BasicTransformer.java:28)
According to my observation the above exception is coming WhenEver my XML file is containg the Elements in Upper Case. The File and code for the same is:
Updated patch, incl. a small patch to UnmarshallHandler amongst other things (that fixes a small problem related to (default) naming conventions when in introspection mode).
Sumit, please have a close look at the file attached. Apart from the patch, it contains several files in a directory xml.c1420, incl. a JUnit test case and three XML files. Basically, it looks like you have not been really familiar with the naming convention Castor by default applies when no mapping file is used (introspection mode).
I added a new XML file (for unmarshalling, used by one of the three test*() methods in the JUnit test case), to show you how the XML is meant to look like for introspection to work successfully. I have added two other XML files taht demonstrate that
a) the sequence of the XML elements within the INT_employee element is irrelevant, as long as the names of the XML elements matches Castor's expectations
b) that if you get an XML element name wrong (e.g. Department_id instead of the expected department_id), Castor will simply not be able to unmarshall this properties' state.
Let me know whether you have any further questions ....