嘿伙计们,我正在尝试创建一个循环,直到用户输入正确的字符选择。当我输入错误的选择时,我收到错误 java.lang.NullPointerException。这可能与我输入的方式有关,但如果我不需要,我不想改变它。选择是类的私有成员。
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