[Android] java.lang.classcastexception org.json.simple.jsonarray cannot be cast to org.json.simple.Jsonobject
Symptom)
While responding json object from the server side to Android side through HttpGet & HttpClient, I got this Unchecked Exception. The problem was neither request to server side nor response from server side. It was that I couldn't get JSON Object and parse it in the Android side.
Root Cause)
By mistake, I imported 2 different kinds of json libraries such as json-simple & json. As you can see in the picture right beneath, I imported org.json(blue box) & org.json.simple(red box) at the same time.
That is the main reason why I got this exception.
Solution)
Just use only one JSON library org.json or org.json.simple like beneath.
While responding json object from the server side to Android side through HttpGet & HttpClient, I got this Unchecked Exception. The problem was neither request to server side nor response from server side. It was that I couldn't get JSON Object and parse it in the Android side.
Root Cause)
By mistake, I imported 2 different kinds of json libraries such as json-simple & json. As you can see in the picture right beneath, I imported org.json(blue box) & org.json.simple(red box) at the same time.
<Picture1> import clauses with org.json(blue box) and org.json.simple(red box)
That is the main reason why I got this exception.
Solution)
Just use only one JSON library org.json or org.json.simple like beneath.
Import
org.json.simple.json.JSONException;
Import
org.json.simple.JSONObject;
Import
org.json.simple.parser.JSONParser;
Import
org.json.simple.parser.ParseException;
|
Comments
Post a Comment