HasMap NullPointerException

I have implemented a HashMap in the following way:


HashMap<Long,ArrayList<MouseEnterListener>> map = new HashMap<>();
map.put( id,new ArrayList<MouseEnterListener>());

When trying to access the map, I get a NullPointerException:


for( MouseEnterListener mouseEnterListener: map.get( id ) ) // Exception here
	mouseEnterListener.invoke( entered );

What I’ve debugged sofar:

  • “id” is correct and the HashMap contains an entry for this id
  • the size of the “map” is 1, while the ArrayList is empty

What’s going wrong here?