无法在 Android 上运行 XML 解析器 Jackson
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;
}
错误是:
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
最佳答案
老问题但是...
Android 没有 javax.xml.stream
包,大多数涉及 XML 的库都需要它。
要自己添加,请将此依赖项添加到您的 build.gradle 文件中:
编译组:'javax.xml.stream',名称:'stax-api',版本:'1.0-2'
这是撰写此评论时的最新版本。你可以查看here更新版本。
关于java - 无法在 Android 上运行 XML 解析器 Jackson,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32889402/