8

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");
4
  • Try this.. link stackoverflow.com/questions/11874919/… Commented Feb 25, 2014 at 12:17
  • Are you getting this error on device/emulator or on your environment (tests)? Commented Feb 25, 2014 at 12:18
  • stackoverflow.com/a/11875002/2337837 Commented Feb 25, 2014 at 12:22
  • thanks everyone for their comments. I was running tests @endriu_l. Commented Feb 25, 2014 at 12:35

1 Answer 1

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/
Sign up to request clarification or add additional context in comments.

2 Comments

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 stackoverflow.com/a/23507579/902217
How do I run the unit tests on a real device?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.