Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HashMap Help

 
J miao
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9067
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Marilyn de Queiroz
Sheriff
Posts: 9067
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic