drawable.equals(null)
The above line calls the "equals (...)" method on the object to be drawn.
So, when drawable is not null and is a real object, then everything goes well, since calling the method "equals (null)" returns "false"
But when "drawable" is NULL, it means calling the method "equals (...)" for a null object, means calling a method for an object that does not exist, therefore it throws a "NullPointerException"
To check if an object exists and is not null, use the following
if(drawable == null) { ... ... }
In the above state, we check that the reference variable "drawable" is null or contains some value (a reference to its object), so it will not throw an exception if drawable is null, checking
null == null
.
Yatendra Goel Jan 09 2018-10-01 14:47
source share