I've made method taking non blank input so I can validate input to my list.
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;
}
I would like to use this in my method which adds objects to my LinkedList. Here is code of this method:
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);
}
The problem is, whatever I've put as login, password or website I'm getting Exception:
Exception in thread "main" java.util.NoSuchElementException: No line found
at 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)
Anyone have a clue what is wrong here? Before I've created method getNonBlankInput everything was ok.