Open LimesKey opened 5 months ago
Also throws,
Exception in thread "main" java.lang.NumberFormatException: For input string: ""
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67)
at java.base/java.lang.Integer.parseInt(Integer.java:671)
at java.base/java.lang.Integer.parseInt(Integer.java:777)
at trashsort.TrashSort.main(TrashSort.java:72)
I fixed the NumberFormatException error with this code but the NoSuchElementException I haven't figured out yet,
do {
System.out.println("Please enter the amount of players: ");
String player_amount_temp = scanner.nextLine();
if (!player_amount_temp.isEmpty()) {
player_amount = Integer.parseInt(scanner.nextLine());
}
else {
player_amount = -5;
}
} while (player_amount < 0 || player_amount >= 10); // only allows 1 - 10 players
Looking more into this, it seems like a better alternative to the Java Scanner is a BufferedReader Console scanner, I will have to do more research though to compare the two.
Can you send the code?
Likely somewhere in this file https://github.com/LimesKey/TrashSort/blob/main/TrashSort/src/main/java/trashsort/TrashSort.java @OrinjCaike, search for scanS.nextline()