简体   繁体   English

Android - java.lang.RuntimeException:将String解析为JSONObject时发生Stub异常

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

I'm getting java.lang.RuntimeException: Stub! 我收到了java.lang.RuntimeException: Stub! exception when I try to parse String to org.json.JSONObject . 我尝试将String解析为org.json.JSONObject My Android API version is 19 . 我的Android API版本是19

Here is my String to be parsed: 这是我要解析的String

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


JSONObject jsonObject = new JSONObject(str); // getting exception at this line
String url = jsonObject.getString("url");

It is probably because you are using android-provided json implementation and you are not running it on an android device or emulator. 这可能是因为你使用android提供的json实现,而你没有在Android设备或模拟器上运行它。

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 使用另一个json库而不是android中嵌入的json库
  • use roboelectric to run your test (if it's a test) without an emulator : http://robolectric.org/ 使用roboelectric来运行你的测试(如果它是一个测试)没有模拟器: http ://robolectric.org/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM