Q:

A 'HttpGet' request forces a close

I use the following code, and when I click a button it force closes. I want to read the response from a web page and show it in a messagebox or a edittext or anything else.
How do I fix this problem?
Code
    HttpGet request = new HttpGet("http://www.google.com");
    HttpClient client = null;
    HttpResponse resp = null;
    try {
        resp = client.execute(request);
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    HttpEntity entity = resp.getEntity();
    MessageBox("Response : "+entity.toString());
}

A:

You are trying to run the HTTP request in your UI code. That's why you got a Force Close. Please try to run it in a service, AysncTask or Thread so the UI thread will not be blocked.
Please refer the example Android HTTP Request in AsyncTask.

