【问题标题】:Android - java.lang.RuntimeException: Stub exception while parsing String into JSONObjectAndroid - java.lang.RuntimeException:将字符串解析为 JSONObject 时的存根异常
【发布时间】:2014-03-27 15:37:20
【问题描述】:

当我尝试将 String 解析为 org.json.JSONObject 时,我收到了 java.lang.RuntimeException: Stub! 异常。我的 Android API 版本是 19

这是我要解析的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");

【问题讨论】:

标签: java android json android-json


【解决方案1】:

这可能是因为您使用的是 android 提供的 json 实现,而您没有在 android 设备或模拟器上运行它。

根据您的实际需要,您可以:

  • 在设备或模拟器上运行它
  • 使用另一个 json 库而不是嵌入在 android 中的那个
  • 在没有模拟器的情况下使用 roboelectric 运行您的测试(如果是测试):http://robolectric.org/

【讨论】:

  • 此外,问题可能出在常规 JUnit 测试的类路径顺序中。我遇到了这样的订单问题,并设法通过这个建议解决了它stackoverflow.com/a/23507579/902217
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-27
  • 1970-01-01
  • 1970-01-01
  • 2013-10-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多