现在的位置: 首页 > 综合 > 正文

\t\tcannot be cast to javax.xml.bind.JAXBElement

2014年07月14日 ⁄ 综合 ⁄ 共 602字 ⁄ 字号 评论关闭

用JAXB技术时,遇到了cannot be cast to javax.xml.bind.JAXBElement 异常。google了一些,发现了一篇国外的文章:

http://metro.1045641.n5.nabble.com/cannot-be-cast-to-javax-xml-bind-JAXBElement-td1051377.html

仔细研究了一下,发现了这样的话,

In your case you don't need to use JAXBElement at all, because your class (Instrucciones) has @XmlRootElement annotation. So you may simply do something like this:

Instrucciones po = (Instriccones) u.unmarshal( new FileInputStream( "src/tests/ejemploAlumnos1.xml" ));

If you want to use JAXBElement for some reason, you can do

JAXBElement<Instrucciones> jxbElem = u.unmarshal( new FileInputStream( "src/tests/ejemploAlumnos1.xml" ), Instrucciones.class);
于是按照他说的,改了下,果然正确。

抱歉!评论已关闭.