Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JAXB 2.1 Unmarshaller error

 
hemanth kollah
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello I am trying to run a program and I get this error message at run time. Please suggest me a solution to get around this error message?

javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"setup"). Expected elements are (none)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:609)
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:244)
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:239)
at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:116)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext$DefaultRootLoader.childElement(UnmarshallingContext.java:1015)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext._startElement(UnmarshallingContext.java:452)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:433)
at com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:137)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:533)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:330)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(XMLNSDocumentScannerImpl.java:779)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1794)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:368)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:834)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1242)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:211)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:184)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:137)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:184)
at com.ec.copec.lw.configuration.ConfigurationHandler.unmarshal(ConfigurationHandler.java:65)
at com.ec.copec.lw.configuration.ConfigurationHandler.getConfigurationWithName(ConfigurationHandler.java:29)
at com.ec.copec.lw.configuration.TestConfiguration.main(TestConfiguration.java:18)
BUILD SUCCESSFUL (total time: 0 seconds)
 
Vipul Bhara
Greenhorn
Posts: 22
Android Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have same question.... I am getting exact error message..
 
hemanth kollah
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This was resolved in http://www.coderanch.com/t/532053/XML/javax-xml-bind-UnmarshalException-unexpected .

Please use XJC commant line utility to create java files from your xsd.
 
Vipul Bhara
Greenhorn
Posts: 22
Android Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I generated it using XJC only.... I am still getting this exception
 
hemanth kollah
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After generating the code from XJC, I changed my Unmarshal code as below.

JAXBContext jaxbContext = JAXBContext.newInstance(jaxbPackageInstance);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
// return (Setup)unmarshaller.unmarshal(dataHandler.getDataSource().getInputStream()); /* Original Code */
JAXBElement<Setup> root = unmarshaller.unmarshal(new StreamSource(dataHandler.getDataSource().getInputStream()), Setup.class);
return root.getValue();

Instead of return (Setup)unmarshaller.unmarshal(dataHandler.getDataSource().getInputStream()); I added the new 2 lines to resolve the unmarshaller error.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic