I have a sudoku 9x9 grid and i am trying to shade the 3x3 cells in the top right, left, center, bottom left and right
I have tried to do it by accessing the points in the 2d array which was fine for position
but if i try it for the other positions it shows errors.
This throws the error?
Could someone tell me why it is doing this or assist in shading the other cells.
This line works on its own - subPanels.setBackground(Color.lightGray);
but if i add -subPanels.setBackground(Color.lightGray);
that is when error happens
Stephan van Hulst
posted 9 years ago
This is because you are trying to dereference an array element before you created it. Think about it, when you call subPanels in the first iteration of your nested loops, this element doesn't exist yet.
You should replace the two setBackground lines with the following: