I'm kinda new to programming and very new to gradle and the pmd-plugin, so please have mercy.
If the user enters a number, scanner.nextLine() will throw a NoSuchElementException in every iteration thus creating an infinite loop.
public class Console {
public int readInteger(String line) {
Integer x = null;
while(x == null) {
try(Scanner scanner = new Scanner(System.in) {
System.out.print(line);
x = scanner.nextInt();
} catch(InputMismatchException exc) {
//error message
} catch(InvalidStateException exc) {
//error message
} catch(NoSuchElementException exc) {
//error message
}
}
return x;
}
}
I will appreciate every helping hand.
Edit: Realized, that my problem occurs in conjuction with the Scanner.nextLine() method. The order doesn't matter, my loop is still an infinite loop with the same NoSuchElementException.