So I already have a method which reads a file which I have converted into a 2d array(therefore the dimensions of the array could be different each time depending on which file I use). Now I am trying to draw a rectangle using this and it wont work. My code is:
public static void drawBoard(String [][] board) {
for (int i = 0; (i < board.length); i++) { //line 88
for (int j = 0; (j < board[0].length); j++) {
int r = board.length;
int c = board[0].length;
double R = new Double(r);
double C = new Double(c);
StdDraw.setXscale(0,C);
StdDraw.setYscale(0,R);
StdDraw.setCanvasSize(500,500);
StdDraw.setPenRadius(0.05);
StdDraw.setPenColor(StdDraw.BLUE);
StdDraw.rectangle((C/2), (R/2), (C/2), (R/2));
StdDraw.close();
}
}
}
What can I do to fix this? How can I get it to draw a rectangle? it says the error is in line 88 and that its a "java.lang.NullPointerException" error.