jaxb 将xml转化为bean时报异常javax.xml.bind.UnmarshalException: unexpected element

前端之家收集整理的这篇文章主要介绍了jaxb 将xml转化为bean时报异常javax.xml.bind.UnmarshalException: unexpected element前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

异常详情

javax.xml.bind.UnmarshalException: unexpected element (uri:”“,local:”student”). Expected elements are (none)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:647)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:243)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportError(Loader.java:238)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement(Loader.java:105)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext @H_301_15@DefaultRootLoader.childElement(UnmarshallingContext.java:1048)atcom.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingCon@H_553_301@text.startElement(UnmarshallingContext.@H_4_403@java:483)atcom.sun.xml.internal.bind.@H_403_475@v2.runtime@H_301_496@.unmarshaller.UnmarshallingContext.startElement(UnmarshallingContext.java:465)atcom.sun.xml.internal.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:135)atcom.sun.org.apache.xerces.inter@H_502_957@nal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509)atcom.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElemen@H_835_1301@t(XMLNSDocumentScannerImpl.java:379)atcom.sun@H_788_1403@.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl NSContentDriver.scanRootElementHook(XMLNSDocumentScannerImpl.java:605)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl @H_403_1558@FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3138)atcom.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl PrologDriver.next(XMLDocumentScannerImpl.java:880)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:117)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl JAXPSAXPa@H_301_1924@rser.parse(SAXParserImpl.java:648)atcom.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:203)atcom.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(Unmars@H_550_2404@hallerImpl.java:175)atjavax.xml.bind.helpers.Ab@H_414_2502@stractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:157)atjavax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:162)atjavax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmars@H_54_3010@h@H_530_3012@a@H_549_3014@l@H_808_3016@l@H_855_3018@erImpl.java:171)atjavax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:189)atcom.morris.xml.util.StudentTest.test(StudentTest.java:28)atsun.refl@H_738_3404@ect.NativeMethodAccessorImpl.invoke0(@H_502_3490@Nativ@H_387_3502@eMethod)atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)atjava.lang.reflect.Method.invoke(Method.java:606)atorg.j@H_258_4030@u@H_463_4032@n@H_349_4034@i@H_848_4036@t@H_275_4038@.@H_640_4040@r@H_381_4042@u@H_326_4044@n@H_658_4046@n@H_921_4048@ers.model.FrameworkMethod 1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner 3.run(ParentRunner.java:238)atorg.junit.runners.ParentRunner 1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access 000(P@H_127_4301@arentRunner.java:53)atorg.junit.runners.ParentRunn@H_189_4403@er 2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

解决办法

  1. Change the root element on your XML to be “student”
  2. Add the annotation @XmlRootElement(name=”student”) to the Student classs.
原文链接:https://www.f2er.com/xml/296180.html

猜你在找的XML相关文章