Null Pointer Exception in Java Programming

NullPointerException is a runtime exception and it is thrown when the application try to use an object reference which has a null value.

For example, using a method on a null reference.


Live Demo

public class Tester {
   public static void main(String[] args) {
      Object ref = null;
      ref.toString(); // this will throw a NullPointerException


Exception in thread "main" java.lang.NullPointerException
	at Tester.main(