简体   繁体   English

无法在Android上运行XML解析器Jackson

[英]Can't run XML parser Jackson on Android

Can't run XML parser Jackson on Android 无法在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;
    }

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. Android没有javax.xml.stream包,这是大多数涉及XML的库所必需的。

To add this yourself, add this dependency to your build.gradle file: 要自己添加,请将此依赖项添加到build.gradle文件中:

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. 您没有正确设置Jackson for Android。 Look at this page Using jackson-dataformat-xml on android . 看看这个页面在android使用jackson-dataformat-xml There are good description how to do it. 有很好的描述如何做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM