Came across this problem writing a program for my Computer Science class. Reproduced here with simpler code:
All but the last call in main() work fine; the last throws a null pointer exception. What is the explanation for this seeming inconsistency?
Current CS undergrad
Enthuware Software Support
posted 9 years ago
You are effectively passing 'null' in the first 3 calls. In the last call you are passing an object, whose toString() is returning a null. The println method checks if the passed object is null (not whether the passed object's toString() returns null), in which case it prints "null" without trying to call any method on it.