I’m writing an Android application and use HashMap<String,MyClass>. According to Java and Android documentation the HashMap should accept both null keys and values. But, strangely, I can’t put null value into my map. In the code:
myMap.put(1, null);
I’m getting the error:
The method put(String, MyClass) in the type HashMap<String,MyClass> is not applicable for the arguments (int, null).
Why is that? What can be wrong and how to fix?
The value is not the issue in this case. Since the HashMap is declared to have a String key and you’re trying to put an int key in, it’s not complaining about the value but the key.