簡體   English   中英

Android - java.lang.RuntimeException:將String解析為JSONObject時發生Stub異常

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

我收到了java.lang.RuntimeException: Stub! 我嘗試將String解析為org.json.JSONObject 我的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");

這可能是因為你使用android提供的json實現,而你沒有在Android設備或模擬器上運行它。

根據您的實際需要,您可以:

  • 在設備或模擬器上運行它
  • 使用另一個json庫而不是android中嵌入的json庫
  • 使用roboelectric來運行你的測試(如果它是一個測試)沒有模擬器: http ://robolectric.org/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM