private InputStream getISFromURL(String url) {
//post
InputStream is=null;
try {
HttpParams params=new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params, 3000);
HttpConnectionParams.setSoTimeout(params, 3000);
HttpClient httpClient=new DefaultHttpClient(params);
HttpPost httpPost=new HttpPost(url);
HttpResponse httpResponce=httpClient.execute(httpPost);
HttpEntity httpEntity=httpResponce.getEntity();
is=httpEntity.getContent();
} catch (Exception e) {
this.context.startActivity(new Intent(this.context, Splash.class));
Log.d("imsoft", "getJSONdataFromURL ="+e.toString());
}
return is;
}
This code works good if the internet connection is alive but when i disconnect my system(which disconnects emulator too) then this method throws UnknownHostException and it is catched in the catch block by opening my Splash.java(splash screen) but at the same time it also give me “Application has stopped unexpectedly Please try again” .
So please give me answer or suggestions that can help me.
As asked by you, here’s my comment in a more formal answer:
Maybe your problem is caused by the fact that you you return null in the case of an Exception.
The caller might throw a NullPointerException if it fails to check that your method result is not null before referencing it.
Try type
adb logcatin a shell to see what happens and where it happens.