I'm trying to get an xml from a url, but I have a bug in HttpResponse.
The URL is for example as follows:
And my code is:
public String getXML (String url){
String result = null;
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet httpPost = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
result = EntityUtils.toString(httpEntity);
} catch (Exception ex) {
Toast errorToast =
Toast.makeText(getApplicationContext(),
"Error reading xml", Toast.LENGTH_LONG);
errorToast.show();
}
return result;
}
I've already set the internet permission in the manifest. The error is in the line:
HttpResponse httpResponse = httpClient.execute(httpPost);
and shows an error:
android.os.NetworkOnMainThreadException
Thank you