Tuesday, June 18, 2013

java.lang.NullPointerException


Description and Symptoms

 java.lang.NullPointerException is a very common Java exception that you can face when developing pure Java, Java EE applications or executing Java programs & games. Exception in thread "main" java.lang.NullPointerException has been around since early JDK days e.g. JDK 1.0.

Sample Error

java.lang.NullPointerException
       at org.ph.javaee.training1.CallerClassA.doSomething(CallerClassA.java:27)

       at org.ph.javaee.training1.NoClassDefFoundErrorSimulator.main(NoClassDefFoundErrorSimulator.java:28)

Possible Causes

  • Java programming problem.
  • Java software (applications, games...) bug.

Troubleshooting and solutions

  • Stack trace and root cause analysis of the affected code. Extra logging and debugging is also recommended.
  • Java code review and bug identification. Addition of proper NULL validation to prevent the problem at the first place.
  • Patch installation of the affected Java software.

References and Case Studies