Hey guys I'm trying to create a loop until a correct character choice is entered by the user. When I enter a wrong choice I get the error java.lang.NullPointerException. It might be with the way I'm inputing but I don't want to change that if I don't have to. choice is a private member of the class.
char wf() {
Scanner input = new Scanner(System.in);
System.out.println("What is your choice? (x/o)");
choice = input.findInLine(".").charAt(0);
while (choice != 'x' && choice != 'o') {
System.out.println("You must enter x or o!");
choice = input.findInLine(".").charAt(0);
}
return choice;
}//end wf
findLineAtreturningnull? If so, that's the problem, cause you callcharAtright after. IffindLineAtwasnull, you will not be able to call methods since there was no object to call methods from (instead there was null), hence the NPE.findLineAtreturnsnullyou only have to understand why. You can do that by reading the JavaDoc and by debugging this method, to see what happens there.