Code Review Stack Exchange is a question and answer site for peer programmer code reviews. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

It work's at Smartphone(Android 2.3.3) but Tablet(Android 4.0) => Force Close!!

 public String getXmlFromUrl(String url) {
        String xml = null;

    try {
        // defaultHttpClient
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url);

        HttpResponse httpResponse = httpClient.execute(httpPost); // HERE FORCE CLOSE, why???
        HttpEntity httpEntity = httpResponse.getEntity();
        xml = EntityUtils.toString(httpEntity);

    } catch (UnsupportedEncodingException e) {
    } catch (ClientProtocolException e) {
    } catch (IOException e) {
    // return XML
    return xml;

Any suggestion with example?

share|improve this question
Try adding yet another catch block like this: catch (Throwable t) { t.printStackTrace(); } Then see what it prints to your error log. – ZeroOne Nov 29 '12 at 15:34
because you are networking on the uithread. next time : read the stacktrace, find the exception name, google it. – njzk2 Jan 15 '13 at 18:18

You should remember this.

From Android 3.x Honeycomb or later, you cannot perform Network IO on the UI thread and doing this throws android.os.NetworkOnMainThreadException. You must use Asynctask .

You have to put your getXmlFromUrl(..) code inside Asynctask method

For more Information Refer this Link

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.