Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

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) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    // 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
add comment

1 Answer

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 http://developer.android.com/reference/android/os/AsyncTask.html

share|improve this answer
add comment

Your Answer

 
discard

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.