我已经制作了采用非空白输入的方法,因此我可以验证我的列表中的输入。public String getNonBlankInput(String text){ Scanner scan = new Scanner(System.in); System.out.println(text); String input = scan.nextLine(); while (input.isEmpty() || input.equals(" ")) { System.out.println("Input is empty."); System.out.println(text); input = scan.nextLine(); } scan.close(); return input;}我想在我的方法中使用它,它将对象添加到我的 LinkedList。下面是这个方法的代码:public void addMenu(){ String log = getNonBlankInput("Enter login: "); String pass = getNonBlankInput("Enter password: "); String web = getNonBlankInput("Enter website: "); Entry newEntry = new Entry(web,log,pass); edao.addEntry(newEntry);}问题是,无论我输入什么登录名、密码或网站,我都会遇到异常:Exception in thread "main" java.util.NoSuchElementException: No line foundat java.util.Scanner.nextLine(Scanner.java:1540)at com.password.PasswordManager.data.InputValidation.getNonBlankInput(InputValidation.java:12)at com.password.PasswordManager.input.MenuImplementation.addMenu(MenuImplementation.java:15)任何人都知道这里出了什么问题?在我创建方法 getNonBlankInput 之前,一切正常。
添加回答
举报
0/150
提交
取消