Why is NullPointerException in Java?


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.

Object ref = null;
ref.toString(); // this will throw a NullPointerException

Updated on: 25-Feb-2020

204 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements