Coding Global Background
Coding Global

Bug Help: Scanner Bug Error - Tried Everything!

Archived a year ago
1 messages
1 members
Created a year ago
Updated a year ago
Open in Discord
A
abombdabomb
Verified
So I ask users through input through these two methods:
public static String whileLoopInputString (Predicate<String> checkCase, String inputMessage, String errorMessage, Scanner scanner) {
        String input = "";

        while (!checkCase.test(input)) {
            System.out.println(inputMessage);
            input = scanner.nextLine();
            if (!checkCase.test(input)) {
                System.out.println(errorMessage);
            }
        }

        return input;
    }


    public static byte whileLoopInputByte (Predicate<Byte> checkCase, String inputMessage, String errorMessage, Scanner scanner) {
        byte input = -1;

        while (!checkCase.test(input)) {
            try {
                System.out.println(inputMessage);
                input = scanner.nextByte();
                scanner.nextLine();
                if (!checkCase.test(input)) {
                    System.out.println(errorMessage);
                }
            } catch (InputMismatchException e) {
                System.out.println(errorMessage);
                scanner.nextLine();
            }
        }

        return input;
    }


I get the scanner bug, mainly when I use the byte, then string input method in that order:
            switch (bytInput) {
                case 1:
                    System.out.println("Rules");
                    break;
                case 2:
                    strCreatedPlayerName = Logic.whileLoopInputString(
                            conditions);
                    break;
                
                case 3:
                    strUsernameToLoadIn = Logic.whileLoopInputString(conditions);
        
                case 4:
                    method();
                    break;
                case 5:
                    bolIsInProgram = false;
                    break;

            }


bytInput also used a method switch is in a loop, if you need code more pls ask