I am building an A* algorithm where i am suppose to add nodes to the grid[][] first ( in my case it is cells[i][j] ). So what i did is i run a loop in order to fill my 2D array with nodes with x and y coordinate filled inside it. But when ever i try to run my code it throws this exception java.lang.NullPointerException
, i know this exception happens when object == null , but somehow i am not able to figure out the reason behind this problem, Here is my code :-
private Node[][] cells;
private void fill(){
for(int i=0;i<rows;i++){
for(int j=0 ; j<cols;j++){
cells[i][j] = new Node(i,j,rows,cols); //throws exception this
line
}
}
}
Please help me out to find the reason behind this.