Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

An exception

 
E Lan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It means you tried to use something that was set to null and that threw a NullPointerException.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12196
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Blake Minghelli
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
E Lan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks applies.These helps me clear.Thanks again
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic