I am creating an application which retrieves images from the web. In case the image cannot be retrieved another local image should be used.
While trying to execute the following lines:
Drawable drawable = Common.getDrawableFromUrl(this, product.getMapPath());
if (drawable.equals(null)) {
drawable = getRandomDrawable();
}
The line if(drawable.equals(null)) throws an exception if drawable is null.
Does anyone know how should the value of drawable be checked in order not to throw an exception in case it is null and retrieve the local image (execute drawable = getRandomDrawable())?
Edited Java 8 Solution:
You can declare
drawablefinalin this case.As Chasmo pointed out, Android doesn’t support Java 8 at the moment. So this solution is only possible in other contexts.