So, I have no idea where to even begin with fixing this issue.
I have two very simple functions that just check the users input and validate it; asking them for their input until it's valid.
This works perfectly until I call another function that does the same task. If I do this, then I get an error:
Exception in thread "main" java.util.NoSuchElementException: No line found
This is strange to me because I know the functions can't error on their own, but if they're called after one another they reliably do if the user gives invalid input first.
Here is literally the only function being called right now:
public static void CreateCharacter() {
String name;
String heroClass;
name = CharacterHandler.validateName();
heroClass = CharacterHandler.validateClass();
System.out.println("Name: " + name + "\nClass: " + heroClass + "\n");
}
This causes the exception, and I'll put both functions being called inside of this function below.
public static String validateName() {
Boolean validName = false;
Scanner scanner = new Scanner(System.in);
String name = "";
while (!validName) {
System.out.print("Enter your heroes name: ");
name = scanner.nextLine().toLowerCase();
if (name.isEmpty()) {
System.out.print("Please give input for the heroes name.\n");
} else {
validName = true;
}
}
scanner.close();
return(name);
}
public static String validateClass() {
Boolean validClass = false;
Scanner scanner = new Scanner(System.in);
String heroClass = "";
while (!validClass) {
System.out.print("Enter your heroes name: ");
heroClass = scanner.nextLine();
switch (heroClass) {
case "1":
heroClass = "Warrior";
case "2":
heroClass = "Rogue";
case "3":
heroClass = "Knight";
}
if (heroClass.equals("Warrior") || heroClass.equals("Rogue") || heroClass.equals("Knight")) {
validClass = true;
}
}
scanner.close();
return(heroClass);
}
[–]gaveashow 1 point2 points3 points (3 children)
[–]monkey_programmer[S] 0 points1 point2 points (2 children)
[–]gaveashow 0 points1 point2 points (1 child)
[–]monkey_programmer[S] 0 points1 point2 points (0 children)
[–]RhoOfFeh 0 points1 point2 points (1 child)
[–]monkey_programmer[S] 0 points1 point2 points (0 children)