java.lang.NoSuchMethodError: java.lang.System.arraycopy using XmlPullParser with Robolectric
Asked Answered
J

2

2

I am trying to test my Android app in Android-Studio with Robolectric. One of my unit tests makes use of XmlPullParser:

InputStream in = new FileInputStream(new File("somefile.xml"));
XmlPullParser parser = Xml.newPullParser();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
parser.setInput(in, null);
parser.nextTag();
while(parser.next()!=XmlPullParser.END_DOCUMENT){
    // ...
}

Here is what happens when I run the test:

java.lang.NoSuchMethodError: java.lang.System.arraycopy([II[III)V
    at org.kxml2.io.KXmlParser.parseStartTag(KXmlParser.java:1145)
    at org.kxml2.io.KXmlParser.next(KXmlParser.java:372)
    at org.kxml2.io.KXmlParser.next(KXmlParser.java:313)
    at xxx.Xxxx.readTag(Xxxx.java:167)

Is it a problem with the implementation of the parser on Robolectric side?

Jonahjonas answered 8/7, 2015 at 7:19 Comment(2)
change your api versionMonreal
@Exbury Thank you! Indeed it works when I switch to API 18!Jonahjonas
M
2

This problems i faced few months back. Change your android API version error will be lost. More info see this.

Monreal answered 8/7, 2015 at 7:33 Comment(0)
J
3

In case somebody stumbles upon this problem, it comes from the version of the SDK.

In the test case just switch from:

@Config(constants = BuildConfig.class, sdk = 21, manifest = "src/main/AndroidManifest.xml")

to:

@Config(constants = BuildConfig.class, sdk = 18, manifest = "src/main/AndroidManifest.xml")

Thanks @Exbury for the tip!

Jonahjonas answered 8/7, 2015 at 7:31 Comment(0)
M
2

This problems i faced few months back. Change your android API version error will be lost. More info see this.

Monreal answered 8/7, 2015 at 7:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.