I am trying to create a 2d array of hashmaps. I do this with the following code:
@SuppressWarnings("unchecked")
Map<String, Boolean>[][] arrayBlock3 = (Map <String, Boolean>[][]) new Map[6][6];
When I try to add elements to the array however, at runtime there is a null pointer exception at the first line adding an element to the array.
The code to add an element is:
arrayBlock3[0][0].put("B", false);
arrayBlock3[0][1].put("G", false);
arrayBlock3[0][2].put("B", false);
arrayBlock3[0][3].put("B", false);
arrayBlock3[0][4].put("G", false);
arrayBlock3[0][5].put("B", false);
Error Message
Exception in thread "main" java.lang.NullPointerException
at main.main(main.java:20)
I would really appreciate your help, thanks.