wood burning stoves 2.0*
The moose likes Cattle Drive and the fly likes HashMap Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "HashMap Help" Watch "HashMap Help" New topic
Author

HashMap Help

J miao
Greenhorn

Joined: Apr 16, 2008
Posts: 3
I am coding the "Assignment OOP-4 (Lookup)", Can you anyone help me to debug NullpointerException? I think I am confuse how to use HashMap.

Following are my main class and look class code, Please I have the abstract class Thing constructed.

(code removed)
[ April 16, 2008: Message edited by: Marilyn de Queiroz ]
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
hi J

Welcome to JavaRanch

Unfortunately, we don't allow code to be posted in this forum ... only pseudocode.

It would be more helpful, however, if you copy and paste the exact error message you are receiving instead of the code.

Remember that when you construct a new HashMap the contents are still null (similar to when you construct an array). So when you construct the HashMap all the keys and all the values are null until you put something in it.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
The other thing to remember is that if you do a get() on a HashMap and the key is not found, you will get a null.
J miao
Greenhorn

Joined: Apr 16, 2008
Posts: 3
Thank you very much for your help! I resolved my issue. HashMap get() was cause of NullPointerException. Method asks for INT parameter but I pass something else.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: HashMap Help