I have a GridMonitorClass that reads in a file to get a basegrid and then from there we have to get a surrounding sum grid, average grid etc, I set up an algorithm to get the surrounding sum grid then in the get function I made (I believe) a copy of that grid and then set the method to return it. However, when the test scenario tries to run the function it spits back a NullPointerException and I'm not sure why... below is my GridMonitor constructor and the getSurroundingSumGrid method as well
GridMonitor Contructor
// Instance Variables
private double[][] baseGrid;
private double[][] surroundingSumGrid;
private double[][] surroundingAvgGrid;
private double[][] deltaGrid;
private boolean[][] dangerGrid;
//Constructor
public GridMonitor(String fileName) {
try {
this.baseGrid = readFile(fileName);
// Get Grid Dimensions for the Remaining Grids
int baseGridXDimension = this.baseGrid.length;
int baseGridYDimension = this.baseGrid[0].length;
// Set Up Surrounding Sum Grid
this.surroundingSumGrid = new double[baseGridXDimension][baseGridYDimension];
for (int i = 0; i < baseGridXDimension; i++) {
for (int j = 0; j < baseGridYDimension; j++) {
if (i == 0 && j == 0) {
this.surroundingSumGrid[0][0] = (2 * this.baseGrid[0][0]) + this.baseGrid[0][1]
+ this.baseGrid[1][0];
} else if (i == 0 && j != 0 && j < baseGridYDimension - 1) {
this.surroundingSumGrid[0][j] = this.baseGrid[0][j] + this.baseGrid[1][j]
+ this.baseGrid[0][j - 1] + this.baseGrid[0][j + 1];
} else if (i != 0 && j != 0 && i < baseGridXDimension - 1 && j < baseGridYDimension - 1) {
this.surroundingSumGrid[i][j] = this.baseGrid[i - 1][j] + this.baseGrid[i + 1][j]
+ this.baseGrid[i][j + 1] + this.baseGrid[i][j - 1];
} else if (i == 0 && j == baseGridYDimension - 1) {
this.surroundingSumGrid[0][j] = (2 * this.baseGrid[0][j]) + this.baseGrid[1][j]
+ this.baseGrid[0][j - 1];
} else if (i == baseGridXDimension - 1 && j == 0) {
this.surroundingSumGrid[i][0] = (2 * this.baseGrid[i][0]) + this.baseGrid[i][1]
+ this.baseGrid[i - 1][0];
} else if (i == baseGridXDimension - 1 && j == baseGridYDimension - 1) {
this.surroundingSumGrid[i][j] = (2 * this.baseGrid[i][j]) + this.baseGrid[i - 1][j]
+ this.baseGrid[i][j - 1];
}
}
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
}
}
Get SurroundingSumGrid Method
public double[][] getSurroundingSumGrid() {
// TODO Auto-generated method stub
double[][] surroundingSumGrid = this.surroundingSumGrid;
return surroundingSumGrid;
}
Edit
I tried just returning this.surroundingSumGrid
and am still faced with a null-pointer exception so I am effectively lost in why this error is happening