我有 2 个类,即 MyClient 和 CustomerUserInterface。MyClient 类有一个 main 方法,我在其中调用 CustomerUserInterface 的方法。
我的客户
public class MyClient {
public static void main(String args[]) {
CustomerUserInterface customerUserInterface = new CustomerUserInterfaceImpl();
Scanner scan = new Scanner(System.in);
customerUserInterface.registerLoginMenu();
int choice = scan.nextInt();
customerUserInterface.performOperationsOnRegisterLoginMenu(choice);
}
}
客户用户界面
public class CustomerUserInterfaceImpl implements CustomerUserInterface {
private CustomerBL customerBl;
private ProductInterface productInterface;
public CustomerUserInterfaceImpl() {
customerBl = new CustomerBLImpl();
productInterface = new ProductInterfaceImpl();
}
@Override
public void registerLoginMenu() {
System.out.println("1. Register");
System.out.println("2. Login");
System.out.println("3. Exit");
}
@Override
public void register() {
Customer customer = CustomerInputHelper.inputCustomer();
boolean status=false;
try {
status = customerBl.registerUser(customer);
}catch (SQLException e) {
e.printStackTrace();
}
if(status) {
System.out.println("Register Success");
login();
}
else {
System.out.println("Register Unsuccessful");
registerLoginMenu();
}
}
我面临的问题是,在第一个 System.out 行之后,我在 login() 方法中遇到错误,即
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
注册成功后,寄存器会调用登录方法,但在登录方法调用之后,我收到上述错误。
我不明白这个问题,因为用户注册了,但在调用登录方法后立即显示错误。
慕妹3146593
qq_花开花谢_0
长风秋雁