I'm trying to make a json object from the result of the googleplaces api. But one line of code is causing me alot of problems. My question is how the heck do i find what the issue is. I can't seem to catch the right exception (im a noob at debugging though). The url that i am passing in has the value: https://maps.googleapis.com/maps/api/place/search/json?location=34.7,-86.5&radius=16000&types=food&name=mcdonalds&sensor=true&key=(myApiCodeWhichImNOTPostingHere)
^i do have the correct apicode and the link works ourside of android.
here is the method in question (highlighted is the line that is causing problems).
public static JSONObject getTheJSON(String url){
JSONObject json=null;
try{
DefaultHttpClient myHttpClient = new DefaultHttpClient();
HttpPost myHttpPost = new HttpPost(url);
//this line below is giving me problems (jumps streight to the catch Exception)
HttpResponse response = myHttpClient.execute(myHttpPost);
//this line above is giving me problems(jumps streight to the catch Exception)
String data = EntityUtils.toString(response.getEntity());
json= new JSONObject(data);
//parse the JSONObject
} catch (UnsupportedEncodingException e){e.printStackTrace();}
catch (ClientProtocolException e){e.printStackTrace();}
catch (IOException e){e.printStackTrace();}
catch (JSONException e) {e.printStackTrace();}
catch (NullPointerException e){ Log.e("My APP", "exception: " + e.getMessage());}
/* jumps to line below (skips the other catch exceptions)
the log reads "null" since i use the "getMessage()" so thats not useful*/
catch (Exception e ) { Log.e("My APP", "exception: " + e.getMessage());}
return json; // returning the JSON object
}
(Edit): Here is the logcat. i think im getting a connection to factory client error
10-16 21:11:30.105: E/My APP(980): exception
10-16 21:11:30.345: E/MapActivity(980): Couldn't get connection factory client