I want to implement the put and get-methods for a multikeymap in Java with two keys pointing to a value. I have written the put-method like this:
public ValueType put(KeyTypeA key1, KeyTypeB key2, ValueType value) {
HashMap<KeyTypeB, ValueType> mappi = outerMap.get(key1);
ValueType oldvalue;
if (mappi.containsKey(key2)) {
oldvalue = mappi.get(key2);
} else {
oldvalue = null;
}
However, when I test this method (I have initialized mappi properly as an instance of my own multikeymap-type) with
mappi.put("xxxxx", 13, "xxxxx");
I get a NullPointerException at
if (mappi.containsKey(key2)) {
What could cause the exception? In my class MultiKeyMap I initialize the multikeymap object in the constructor, so that should be ok.