I'm trying to use a text file to populate a 2D array for a game board. I can't seem to get the reader to actually read the file though. I keep getting the following error:
"Unable to open file 'C://git/cse116f16/src/boardpieces/board.txt'Exception in thread "main" java.lang.NullPointerException".
I know it's because I'm not using the correct syntax for the filepath, but I can't for the life of me figure out what that should be. I have it stored at C:\Users\myname\git\cse116f16\src\boardpieces\board.txt.
What is the string I would need to pass into FileReader to read this file?
EDIT: Here's the method, maybe the problem isn't what I think it is.
Also it should be noted this is on a git repository so I need to be sure it can be read by everyone who pulls it.
public Character[][] populateArray(String fileName){
String line = null;
Character[][] retVal = new Character[26][28];
int lineNum = 0;
try {
FileReader fileReader = new FileReader(fileName);
BufferedReader bufferedReader = new BufferedReader(fileReader);
//Assigns each character to it's corresponding place in the array
while((line = bufferedReader.readLine()) != null) {
for (int i = 0; i < 26; i++){
retVal[lineNum][i] = line.charAt(i);
}
}
bufferedReader.close();
}
catch(FileNotFoundException ex) {
System.out.println("Unable to open file '" + fileName + "'");
}
catch(IOException ex) {
System.out.println("Error reading file '" + fileName + "'");
}
return retVal;
}
public void populateBoard(){
String path = "C:\\Users\\myname\\git\\cse116f16\\src\\boardpieces\\board.txt";
Character[][] arr = populateArray(path);
//the rest of the method...