What is a NullPointerException, and how do I fix it?

Created by Vincent RamdhanieLinked to 87.5m issues across 125 teams


A NullPointerException is an error that occurs when a reference variable is set to null, meaning that it is not referencing any object. This can happen when a reference variable is declared but not initialized, or when a method is called on an object that is null. To fix this error, the reference variable must be initialized to an object, or the method must be called on a valid object..