File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes hashMap question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "hashMap question" Watch "hashMap question" New topic
Author

hashMap question

rick simpson
Greenhorn

Joined: Oct 15, 2008
Posts: 8
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

Joined: Oct 06, 2007
Posts: 338
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

Joined: Oct 13, 2005
Posts: 39053
    
  23
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.
 
 
subject: hashMap question