Ok guys so i am trying to read in from 1 out of 3 files normally with out the if ... else clause
just Scanner myScanner = new Scanner(new File("maze1.txt")); would run the problem, but i want the user to select what maze he/she would like to run
public class Main {
private static Scanner myScanner;
public static void main(String[] args) throws FileNotFoundException {
System.out.println("Please Enter 1,2 or 3 to pick the different maze you would like being solved.");
Scanner myScannerinput = new Scanner(System.in);
int Mazenumber = myScannerinput.nextInt();
if(Mazenumber == 1){
Scanner myScanner = new Scanner(new File("maze1.txt"));
}
else if(Mazenumber == 2){
Scanner myScanner = new Scanner(new File("maze2.txt"));
}
else if(Mazenumber == 3){
Scanner myScanner = new Scanner(new File("maze3.txt"));
}
else{
System.out.println("You did not choose one of the 3 mazes");
}
int numRows = myScanner.nextInt();
int numCols = myScanner.nextInt();
myScanner.nextLine();
int startX = 0;
int startY = 0;'
Please Enter 1,2 or 3 to pick the different maze you would like being solved.
Exception in thread "main" java.lang.NullPointerException
at Main.main(Main.java:33)
myScanner.nextLine();should be generating a compiler error, becausemyScanner's scope each time is only within theifandelse ifblocks.ifladder.staticvariablemyScannerbefore. Thanks for pointing that out.