Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't run XML parser Jackson on Android

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
like image 417
NickUnuchek Avatar asked Nov 30 '22 17:11

NickUnuchek


1 Answers

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.

like image 65
Brad P Avatar answered Dec 04 '22 12:12

Brad P