Your problem would be much easier to debug if you included the exact stack trace.
In general, NullPointerException occurs when you try to invoke a method of what you think is a reference to an object but is really a null reference.
For example, the following code would produce a NullPointerException:
In this case, the stack trace would have the line with println on it at the top of the trace, because that is where the NullPointerException is thrown. The null reference is not a reference to an object, so there are no methods that can be invoked on it; in particular, the name.length() in the above example is what triggers the NullPointerException here.