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
Joined: Sep 23, 2000
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.