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 f
drawable.equals(null)
The above line calls the "equals(...)" method on the drawable object.
So, when drawable is not null and it is a real object, then all goes well as calling the "equals(null)" method will return "false"
But when "drawable" is null, then it means calling the "equals(...)" method on null object, means calling a method on an object that doesn't exist so it throws "NullPointerException"
To check whether an object exists and it is not null, use the following
if(drawable == null) {
...
...
}
In above condition, we are checking that the reference variable "drawable" is null or contains some value (reference to its object) so it won't throw exception in case drawable is null as checking
null == null
is valid.