how do i figure out how to debug this? HttpResponse

∥☆過路亽.° 提交于 2019-12-11 02:56:40

问题


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

回答1:


Instead of using e.getMessage(), use e.printStackTrace() (outside of the Log.e() method, but within the catch clause) so you can trace what the real problem is. If you do not get any wiser from that, please post the stacktrace here.

Edit (see commments):

My LogCat (without filters) always displays the stacktraces in a correct way, but after a bit of searching it seems that that is not always the case: See this SO question.

You should use three(!) arguments with the Log.e method. Example:

Log.e("My APP", "exception", e);



回答2:


You might want to check your SSL setup. You are calling a https:// url




回答3:


I ran your code in eclipse and it ran fine giving me a valid response. I think this is probably SSL related. You could enable SSL debugging by doing -Djavax.net.debug=all

Can you paste the output log after enabling SSL debugging?



来源:https://stackoverflow.com/questions/12904818/how-do-i-figure-out-how-to-debug-this-httpresponse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!