I am sure I have written about NullPointerException before, and I shall repeat myself.
BTW: Is there an FAQ on the Ranch about NullPointerException?
It usually means you are trying to use an object which does not exist. Unless you have a line like:-
NullPointer, (like the other two exceptions I keep going on about, ArithmeticException and XYZIndexOutOfBoundsException) means there is an error in your coding somewhere.
Find the line number where your exception occurs. You should be able to read that from the error message.Look at that line and count every object which is, or might be, used in it.Enter a line, 1 line before that line, where you print out all these objects: something like this: System.out.printf("ObjectA: %s ObjectB: %s ObjectC %s%n", objectA, objectB, objectC);//test
Look at your printout. An object with details, eg class name and hash code, exists.An object without details, doesn't exist. It will usually say "ObjectC: null"Go back over the history of any "null" objects, and make sure they have actually been instantiated.Voila. Easy. Two likely reasons for a null object:
1: forgetting to instantiate it in the first place2: Obscuring (is that the right term) it by inadvertently re-declaring it as a local variable. I read somewhere, I forget where, that one spends very little time correcting errors found in debugging. It is finding them that is the problem.
CR