I am having an issue of verifying that the data from a csv file has been stored by a 2D array. When I try to display the array in my main, I get a Null Pointer Exception.
I have tried various youtube videos and looking on stackoverflow.
My add to 2D array code:
public static void addTo2DArray(String[] tmpArray, int minCapacity) {
int row = 0;
int columns = 0;
if ((minCapacity > row)) {
row = (row * 3) / 2 + 1;
String[][] newArray = new String[row][columns];
for (int i = 0; i < crime2DArray.length; i++) {
for (int j = 0; j < crime2DArray[i].length; j++) {
newArray[i][j] = crime2DArray[i][j];
}
}
crime2DArray = newArray;
}
crime2DArray[minCapacity - 1] = tmpArray;
}
Also my main code to display public class TestUSCrime {
public static void main(String[] args) {
for (int row = 0; row < crime2DArray.length; row++) {
for ( int column = 0 ; column <crime2DArray[row].length; column++) {
System.out.print(crime2DArray[row][column] + " ");
}
System.out.println();
}
}
}
I am expecting to display the csv file in a 2D array but the output I am getting is the Null Pointer Exception that takes me back to line 15 of my main.
Line 15 is: for (int row = 0; row < crime2DArray.length; row++) {