• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HashMap Help

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic