5

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
NickUnuchek
  • 11,794
  • 12
  • 98
  • 138
  • If you are asking "How to fix this error?", what is "_How to rename main Name of the project in Android Studio?_" question doing at the beginning of the post? And your code is incomplete, it won't compile. Please, create a [mcve]. – Roman Oct 01 '15 at 15:54
  • @Roman, sorry, didn't delete previous question – NickUnuchek Oct 01 '15 at 16:08

2 Answers2

22

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.

Brad P
  • 390
  • 3
  • 10
0

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.

Community
  • 1
  • 1
Ilya Tretyakov
  • 6,848
  • 3
  • 28
  • 45