aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "An exception" Watch "An exception" New topic
Author

An exception

E Lan
Greenhorn

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(Card.java:42)

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
Bartender

Joined: Oct 02, 2003
Posts: 11402
    
  16

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;

myName.length()

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(Card.java:42)
That tells you that the offending null variable is being used on line 42 of Card.java


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

Joined: Mar 15, 2004
Posts: 11
Thanks applies.These helps me clear.Thanks again
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: An exception