File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes An exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "An exception" Watch "An exception" New topic

An exception

E Lan

Joined: Mar 15, 2004
Posts: 11
Hi,I am a beginner.
My program has this exception.

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

What does this exception mean?What should I deal with this program?
Thanks applies.
Darin Niard
Ranch Hand

Joined: Jun 08, 2004
Posts: 118
It means you tried to use something that was set to null and that threw a NullPointerException.
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

any variable (that is not a primitive) is actually a reference to an object. in other words, the object is a house, and the variable that you have is a piece of paper with the street address of the house.

when you get this error, you have the paper, but no address is written on it. you're telling someone to go to the address on the paper and open the door - but they cant.

if you have something like

String myName;


you will get this error. you have a reference to a string, but you never CREATED the string and set this reference to point to it.

does that help?

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Blake Minghelli
Ranch Hand

Joined: Sep 13, 2002
Posts: 331
Also, the compiler is usually good at telling you exactly where the exception is coming from:
at Card.main(
That tells you that the offending null variable is being used on line 42 of

Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
E Lan

Joined: Mar 15, 2004
Posts: 11
Thanks applies.These helps me clear.Thanks again
I agree. Here's the link:
subject: An exception
It's not a secret anymore!