Reputation: 25
This keeps giving a null pointer exception... I feel like I'm missing something. This is a HashMap<Character, Integer>
, by the way. Maybe it's a wrapper/primitive thing? I don't know.
int amount = 0;
for (int i = 0; i < aMap.size(); i++){
if (!aMap.get(i).equals(null))
if (aMap.get(i).equals(c))
amount++;
}
Upvotes: 0
Views: 42
Reputation: 3279
aMap.get(i).equals(null)
throws a NPE if aMap.get(i)
is null. You have to use ==
to test for reference equality when testing for null:
if (aMap.get(i) != null)
Upvotes: 2