Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - java.lang.RuntimeException: Stub exception while parsing String into JSONObject

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");
like image 987
talha06 Avatar asked Feb 25 '14 12:02

talha06


1 Answers

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/
like image 137
Pierre Rust Avatar answered Sep 22 '22 12:09

Pierre Rust