Reputation: 2340
Whenever I run this method the print goes perfectly fine so the argument is passed and not null. Still it gives a NullPointerException when the argument is added to the children ArrayList (which is a part of the class). Why is this?
public void addChild(_Node n){
System.out.println("Add " + n.getClass().getSimpleName() + " to " + this.getClass().getSimpleName());
children.add(n);
}
Upvotes: 0
Views: 80
Reputation: 6730
Check to see if children
has been instantiated correctly. This is a common mistake beginners make.
Upvotes: 3
Reputation: 2299
NullPointerException when the argument is added to the children ArrayList
children
is null.
n
is not null and you can add null objects to most Lists.
Upvotes: 3