NullPointerException

The ghost of NullPointerException was floating from class to class. An account of how i caught it and kicked its butt.

Was passing 0 as reference to a method which was then seeking value against 0 as key in a map when there was no such key-value pair in the map. Jumped through 4 classes, many psvm's written in each class to test each separately... and 2 days later I realize that the first entry being passed in the while loop is 0 which is hooping thru methods and finally seeking value in a map for the key=0. Didn't give up though ... tracked the damn exception and can sleep at 2:30 AM.

Lesson learnt:
1. be sure of control flow when a class is getting loaded.. static blocks can be defined to call any static method which need to run at time of class loading itself, else they would be inaccessible in case there is no need to initialize class.

2. NullPointerException means involvement of null. Immediately check data involved and if the method in question is seeking for a data which does not exist.. basics!

3. Understand the exception being thrown and look at stacktrace carefully: climb down the ladder by clicking on each line of the stack.

A good day though coz program ran without error or warning!

K.O. (=kush out) 

Comments

Popular Posts