Re: Map.get(key) returns null after inserting key



In a previous article, "Mize-ze" <zahy.bnaya@xxxxxxxxx> said:
Hello,
I am inserting a key and a object into a Map. later in the code I try
to retrieve the object by calling
Map.get(key) and I get a null.
I can't see where is my problem...

I only had to read this far to guess what the problem is - you haven't
implemented hashCode on your key class, or if you have, you haven't
implemented it properly, and you're using HashMap.

I know this, because I made the same mistake (AGAIN) a few weeks ago. I
changed something from TreeSet to HashSet and things weren't working the
way I expected.

--
Paul Tomblin <ptomblin@xxxxxxxxx> http://blog.xcski.com/
It might not be practical, it might not be a good idea, but it could work.
Sort of like Windows.
-- berry
.



Relevant Pages

  • Re: XP Client Cant Log In To Server After Initial Setup
    ... AddUsersToLocalAdmin-- calling NetLocalGroupAddMembers(Administrators, ... Settings\Stephanie Bellone] to the profile dir map ... CWizard::DeleteCSAllUsers-- deleting ...
    (microsoft.public.windows.server.sbs)
  • Re: CMap causes program to crash on exit
    ... And in some cases you just want to know if an element is in the map without actually inserting as part of that check and then you use find. ... IntStringMap data; ... fault of other part of the code (even if it seems not clear basing on ...
    (microsoft.public.vc.mfc)
  • Re: pointer to map is not behaving properly across function calls (for VC++ compiler)
    ... >> I am calling a function which returns pointer to a map. ... >> containing pointer to a class xyz. ...
    (comp.lang.cpp)
  • Re: ct_get_data() fails
    ... calling ct_get_dataon column 2 ... Only those columns following the last bound column are available to ... but can use ct_get_data to retrieve the data ... Replication Server raising the error. ...
    (comp.databases.sybase)
  • Re: Maps
    ... I have unsigned char constants defined in my class... ... I want these data to be populated in a map.. ... i should retrieve Value1... ... const STRMAP m2; ...
    (microsoft.public.vc.stl)

Loading