• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hashMap question

 
rick simpson
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have the following class:



I get an NullPointerExpection when I try using the recordEntry method from a jUnit test case. The constructor works fine. The hand off to the method is fine. Problem is at the put.

Here's the jUnit test:



Any suggestions welcomed. I'm stumped.

[edit]Add code tags. CR[/edit]
[ October 15, 2008: Message edited by: Campbell Ritchie ]
 
Paul Campbell
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your code

you have only created a reference variable called entries to store the reference to the HashMap object... you still haven't created the entries object on the heap until you peform


[ October 15, 2008: Message edited by: Paul Campbell ]
 
Campbell Ritchie
Sheriff
Posts: 48386
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch, Rick Simpson

You will have to get into the habit of initialising every single field in a constructor, then you will get far fewer NullPointerExceptions.

By the way: We have a button marked CODE; please use it around code; I have edited your post to show the effect, that it preserves indentation and makes the code much nicer to read.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic