I am using a method getBitmap to display images. As I am using this as a method,if it returns bitmap display an image but if it returns null,catch an exception. But if url entered is wrong also, it should handle the FileNotFoundException. How to handle two exception and display in UI?
public Bitmap getBitmap(final String src) {
try {
InputStream stream = null;
URL url = new URL(src);
java.net.URL url = new java.net.URL(src);
URLConnection connection = url.openConnection();
InputStream input = connection.getInputStream();
myBitmaps = BitmapFactory.decodeStream(input);
return myBitmaps;
} catch (IOException e) {
e.printStackTrace();
Log.e("IO","IO"+e);
return null;
}
catch(OutOfMemoryError e1) {
e1.printStackTrace();
Log.e("Memory exceptions","exceptions"+e1);
return null;
}
}
In Activity, i've given like this
Bitmap filename=service.getBitmap(url_box.getText().toString());
if(file_name!=null)
{
displaybitmap(file_name);
}
else
{ //Toast.makeText("Memory Error");
//my question is how to handle two exception in UI where memory error and also
// when entered url is wrong, file not found exceptions also to handle.
}