How to check if object is null?
android, java
Solution
Edited Java 8 Solution:
final Drawable drawable =
Optional.ofNullable(Common.getDrawableFromUrl(this, product.getMapPath()))
.orElseGet(() -> getRandomDrawable());
You can declare `drawable` `final` in this case.
As Chasmo pointed out, Android doesn't support Java 8 at the moment. So this solution is only possible in other contexts.
Problem
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()`)?