Can't run XML parser Jackson on Android
import android.content.Context;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;
in onCreate(){
ObjectMapper xmlMapper = new XmlMapper();
Channel root = xmlMapper.readValue(stringXML, Channel.class);
}
@JacksonXmlRootElement(localName = "channel")
public static class Channel {
public List<Item> channel;
}
public static class Item {
@JacksonXmlProperty(localName = "item")
public String item;
}
Error is :
java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/xml/stream/XMLInputFactory;
Caused by: java.lang.ClassNotFoundException: Didn't find class "javax.xml.stream.XMLInputFactory" on path: DexPathList
Old question but...
Android doesn't have the javax.xml.stream
package, which is required for most libraries involving XML.
To add this yourself, add this dependency to your build.gradle file:
compile group: 'javax.xml.stream', name: 'stax-api', version: '1.0-2'
This is the latest release as of writing this comment. You can check here for updated versions.
You didn't setup Jackson for Android correctly. Look at this page Using jackson-dataformat-xml on android . There are good description how to do it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.