| 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: 9033
|
|
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: 9033
|
|
|
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.
|
 |
 |
|
|
subject: HashMap Help
|
|
|