Definition
A null pointer exception (NullPointerException) is a runtime error that happens when a program tries to use data or a feature through a reference that points to nothing (Null). It's the name used in languages like Java, and if it isn't handled, the program stops.
What Happens When You Send Someone on an Errand With an Empty Address
In a computer, a variable is like a note or an address book that says where something is. For example, when you tap a friend's name in your phone's contact list, the computer reads the phone number note linked to that name and makes the call.
But what if the friend's name is in the list, yet the actual phone number field is "empty (Null)"? If you tell the computer to press the call button anyway, it tries to dial a number that doesn't exist, gets badly confused, and stops working.
Here, a "pointer" is a finger pointing at where a piece of data sits in memory, and "null" means nothing is there. It's like telling someone to pick something up by pointing a finger at thin air. You're holding the paper (the variable), but the actual contents (the object) the paper points to are completely empty.
The Real Reason Apps Suddenly Crash
You've probably had a phone app go dark without any warning, or kick you back to the home screen. One common cause of those forced shutdowns is exactly this error.
For example, say your internet connection is shaky and the app can't get profile pictures or comment data from the server in time. If the app is told to draw the screen when there's no data ready, the computer tries to force open an empty space and throws an error.
If no safeguard has been prepared, the program can't run its next line of code and just collapses on the spot. That's why developers need to write checks done in advance (null checks) that first ask, "Could this value be empty?" before they handle any data.
To Be a Little More Precise: The Billion-Dollar Mistake
In the history of computer programming, the idea of null has a very famous story. In 1965, Tony Hoare, a renowned British computer scientist, added the null reference to a programming language for the first time, as an easy way to express "no value exists."
Decades later, though, he admitted in public that his invention was a billion-dollar mistake. Because null values were allowed, countless crashes and security flaws showed up in software around the world, and fixing them cost an astronomical amount.
Many newer languages, such as Kotlin and Swift, come with clever safeguards built in to escape this long-running pain. A technique called null safety is spreading, which strictly checks whether a variable can hold an empty value from the moment a programmer writes the code.
Common misconceptions
Null means exactly the same thing as the number 0 or an empty string ("").
The number 0 is an actual value, "zero," and an empty string is a real thing, a string of length zero. Null means complete absence, with nothing even allocated in memory.
Where you meet it
It happens when you try to load the nickname from the info of a visitor who isn't logged in.
It happens when you try to show the body text of a post that has already been deleted from a message board.
In one sentence
It's a classic programming error that happens when you ask for data through a reference that points to nothing.