samedi 7 mars 2015

Filling a 2D array with characters using data input from file - Java



I am trying to fill an array of chars using data input from file, while parsing the file I am also trying to store some values, but things are not working.


This is my code:



char[][] board = new char[ROWS][COLS];

for( int row = 0; row < board.length; row++){
for (int col = 0; col < board[row].length ; col++){
if (fileScan.hasNext()){
board[row][col]= fileScan.next().charAt(0);
if(board[row][col] == START){
startingPoint = new Point(row, col);
}
if(board[row][col] == END){
endingPoint = new Point(row, col);
}
}


}


Given that then input file has



1 O O
O O O
O X 2


this is what i get when I run it:



O O
O X

java.lang.NullPointerException



Aucun commentaire:

Enregistrer un commentaire