• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Constructor initialization results in Null Pointer

 
John Davis
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know why I get a Null Pointer for an object which I setup in my Constructor.
Here is the code which works:

Here is the code which results in a Null Pointer when I try to reference the object.

What's the idea here, and what am I doing wrong when I set the object up in the constructor?
 
Steve Morrow
Ranch Hand
Posts: 657
Clojure Spring VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not really a constructor if it returns something, so try removing the "void" return type.

HTH!
[ June 04, 2003: Message edited by: Steve Morrow ]
 
John Davis
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve,
Thanks a lot. I thought if I used void, that meant that it returned nothing. But I see that the compiler does not treat my "void" method as a constructor and therefore it never gets called, resulting in a null pointer.
Thanks again,
John Davis
There are 01 types of people in the world. Those who understand binary, and those who don't...
 
Rick Critchett
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like a bit of a kooky compiler.
No error or warning and then odd constructor behavior for your syntactic mistake?
What compiler are you using?
-rick
 
John Davis
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rick
I'm using javac from J2SE1.4.1_02, but I don't think its a kooky compiler. Based on another reply I received, apparently my "constructor" method wasn't really a constructor, and wasn't being called, because it had "void" in its footprint.
John Davis
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic