NullPointerException's are thrown when operation is performed on a null value. You should not throw it. You have to prevent it from happening. One way is check if a value is null before doing anything with it. For eg: if you have a null string. If you do a string.length(), this will throw a nullpointerexception.