跪求高手帮忙解决这个异常!
这是用jaxb绑定一个xml文件所出现的异常:
Exception in thread "main" java.lang.ClassCastException: javax.xml.bind.JAXBElement cannot be cast to com.part.jaxp.Users
at com.part.jaxp.JavaTest.main(JavaTest.java:15)
package com.part.jaxp;
import java.io.File;
import java.util.List;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
public class JavaTest {
public static void main(String[] args) throws JAXBException {
JAXBContext jc = JAXBContext.newInstance("com.part.jaxp");
Unmarshaller unmarshaller = jc.createUnmarshaller();
Users users= (Users)unmarshaller.unmarshal(new File( "src/user.xml"));
//Books books = collection.getBooks();
List<User> userList = users.getUser();
for (User user : userList) {
System.out.println(user.getName());
}
}
}