我已經(jīng)制作了采用非空白輸入的方法,因此我可以驗證我的列表中的輸入。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);}問題是,無論我輸入什么登錄名、密碼或網(wǎng)站,我都會遇到異常: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)任何人都知道這里出了什么問題?在我創(chuàng)建方法 getNonBlankInput 之前,一切正常。
獲取非空白輸入的方法
慕尼黑8549860
2021-06-11 18:08:44