Xstream把xml转换成java对象的异常:java.lang.NoClassDefFoundError: org/xmlpull/v1/XmlPullParserFactory

1.抛出的异常信息如下:

Xstream把xml转换成java对象的异常:java.lang.NoClassDefFoundError: org/xmlpull/v1/XmlPullParserFactory_第1张图片

2.原因:


应该改成:

  

XStream xstream=new XStream(new DomDriver()); //注意:不是new Xstream(); 否则报错:java.lang.NoClassDefFoundError: org/xmlpull/v1/XmlPullParserFactory
		xstream.processAnnotations(PersonBean.class); //如果是用注解的方式,这句不能少
		PersonBean person=(PersonBean)xstream.fromXML(xmlStr);
		System.out.println("person=firstname=="+person.getFirstName());
		return person;

你可能感兴趣的:(java,xml)