7

I'm getting java.lang.RuntimeException: Stub! exception when I try to parse String to org.json.JSONObject. My Android API version is 19.

Here is my String to be parsed:

{
    "url": "http://www.google.com",
    "cookie": "012121",
    "filename": "Google"
}


JSONObject jsonObject = new JSONObject(str); // getting exception at this line
String url = jsonObject.getString("url");
talha06
  • 6,206
  • 21
  • 92
  • 147

1 Answers1

13

It is probably because you are using android-provided json implementation and you are not running it on an android device or emulator.

Depending on your real need you can either :

  • run it on a device or emulator
  • use another json library instead of the one embedded in android
  • use roboelectric to run your test (if it's a test) without an emulator : http://robolectric.org/
Pierre Rust
  • 2,474
  • 18
  • 15
  • Also, the problem can be in classpath order for regular JUnit tests. I faced with such order issue and was managed to solve it with this suggestion https://stackoverflow.com/a/23507579/902217 – CAMOBAP Jan 25 '22 at 14:53
  • How do I run the unit tests on a real device? – Edward Falk May 16 '23 at 18:50