• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

creating a unique list

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Code Snippet:


the code above loops through a map and prints out a list of Station. i.e.


depending on a map given, i sometimes get a duplicate station, i.e. "Finchley" would be printed twice somewhere in the list... so to make a unique list
i decided to use HashSet and use its add method to add all the element to the set.

Say i declare a HashSet someSet as an instance member right at the top of my code...

then in the code given i replace //HERE with someSet.add(s);

this compiles fine but when executed it causes my code to throw NullPointerException any idea why this is happening? and the compliler say that the exception is caused by the line someSet.add(s);

thanks
[ September 25, 2006: Message edited by: Firman Drage ]
 
Max Vandenburg
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
:roll: forget the above ... i think i found out why... thanks anyway
 
All of the following truths are shameless lies. But what about this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic