XmlPullParserException error

379 views
Skip to first unread message

Jia Kang

unread,
Jun 12, 2017, 5:40:59 PM6/12/17
to XStream User
Hello,

I'm trying to use xstream to print xml format. The main code is like:

final XStream xstream = initializeXStream();
String message = xstream.toXML(newValue);

protected XStream initializeXStream() {
final XStream xstream = new XStream();
return xstream;
}

But for each run, it always says error,

java.lang.NoClassDefFoundError: org/xmlpull/v1/XmlPullParserException
at com.thoughtworks.xstream.XStream.<init>(XStream.java:350)
Caused by: java.lang.ClassNotFoundException: org.xmlpull.v1.XmlPullParserException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)

My build.gradle is like:

compile name: 'kxml2-2.3.0'
compile name: 'xml-apis-1.3.02'
compile name: 'xpp3_min-1.1.4c'
compile name: 'xmlpull-1.1.3.1'
compile "com.thoughtworks.xstream:xstream:1.4.7"

Any one knows where might be wrong?

Thanks very much.

Jörg Schaible

unread,
Jun 12, 2017, 7:32:22 PM6/12/17
to xstrea...@googlegroups.com
Hi,
Too many XmlPullParsers. You have class loader issues. See,
XmlPullParserException is part of the XML Pull *API*. The "official" API
classes are contained in xmlpull-1.1.3.1.jar. However, kxml2-2.3.0.jar
contains an own set of it and xpp3_min-1.1.4c.jar another (partial) set.

You're using XStream with the default driver, i.e. it will use the
XmlPullParser factory to detect an implementation using a pseudo
implementation of the Java service API. However, the factory instance might
eigher come from the official API or from kXML2, but it seems that the
initialization of the XMLPullParser fails here somewhere on its way.

So you should decide whether you wan't to use Xpp3 or kXML2. Either use
xpp3_min and xmlpull or kxml2 or kxml2_min and xmlpull.

Cheers,
Jörg

BTW. None of this requires xml-apis.



Reply all
Reply to author
Forward
0 new messages