I have this code in android and java. I want to show a dialog to the user when his Internet connection has problems or the website is inaccessible. I try to put my code into a try-catch
block but yet when the Internet connection has a problem my app is closed. I want to show a message to the user, not to close the app.
HttpPost ht = new HttpPost("http://yahoo.com");
HttpClient hc = new DefaultHttpClient();
HttpResponse hr = null;
try {
hr = hc.execute(ht);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String htmlTemp = "";
try {
HttpEntity he = hr.getEntity();
htmlTemp = new String(EntityUtils.toString(he));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}