Can anyone help me understand what is going wrong?
unreported exception org.json.JSONException; must be caught or declared to be thrown
jsonObj = new JSONObject("{\"count\":3939,\"has_more\":true,\"map_location\":{\"lat\":0.60996950000000183,\"lon\":-27.568517000000003,\"panoramio_zoom\":16},\"photos\":[{\"height\":375,}]}"); //creates the JSON object from the jsonString, for parsing
^
1 error
I'm using org.json, and I think I have everything set up correctly. I'm trying to create a JSONObject using the constructor in org.json that takes a source string, and I keep getting this exception. I'm not sure what is wrong with the string that I am sending in. Thanks
Catch your Exception by creating try and catch:
try {
JSONObject jsonObj = new JSONObject("{\"count\":3939,\"has_more\":true,\"map_location\":{\"lat\":0.60996950000000183,\"lon\":-27.568517000000003,\"panoramio_zoom\":16},\"photos\":[{\"height\":375,}]}");
System.out.println(jsonObj);
} catch (JSONException e) {
//some exception handler code.
}
Or either throws your exception to caller method:
public String yourMethod(String jsonString) throws JSONException
constructor declares to throw org.json.JSONException
so you must handle it (catch & handle or rethrow to let caller handle it)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With