hashmap - Java multikeymap put-method -
I put in Java for a multimimate and applied methods with two keys pointing to a value Want to do I have written this way:
public value type type (keypie key 1, keytype key key 2, value type value) {Hashmap < Ketip B, Value Type & gt; Mappi = outerMap.get (key1); ValueType Old Price; If (mappi.containsKey (key2)) {oldvalue = mappi.get (key2); } Else {oldvalue = null; }
However, when I test this method (I have started the map properly as my own multi-type type)
mappi.put "xxxxx", 13, "xxxxx"); I get a NullPointerException at
me
(if mappi.containsKey (key2)) { what is the reason Exceptions? In my class multicomap I initialize the multimimize object into the constructor, so it should be fine.
If this is not a homework, you can use it, instead of resuming it from scratch .
To answer your question, I suspect that in error hashmap and lieutenant; Ketip B, Value Type & gt; Mappi = outerMap.get (key1);
. If there is no value in key 1 in external mark
, then mappi
will be zero, from which NullPointerException
Comments
Post a Comment