0

I'm working with a linked list and getting this error message:

NoSuchElementException: No line found

public static void main(String[] args) {
Scanner Input = new Scanner(System.in);
String selection = null;

    do {
        System.out.println("\n\t\tMENU DISPLAY\n-----------------------------------------------");
        System.out.println("a\tShow all records");
        System.out.println("\nr\tRemove the current record");
        System.out.println("\nf\tChange the first name in the current record");
        System.out.println("\nl\tChange the last name in the current record");
        System.out.println("\nn\tAdd a new record");
        System.out.println("\nd\tAdd a deposit to the current record");
        System.out.println("\nw\tMake a withdrawal from the current record");
        System.out.println("\nq\tQuit");
        System.out.println("\ns\tSelect a record from the record list to become the current record");
        System.out.print("\nEnter a command from the list above, or q to quit: ");
        selection = Input.nextLine();

        switch(selection) {
            case "a":
                showAll();
                break;
            case "r":
                removeCurrent();
                break;
            case "f":
                changeFName();
                break;
            case "l":
                changeLName();
                break;
            case "n":
                addNew();
                break;
            case "d":
                deposit();
                break;
            case "w":
                withdraw();
                break;
            case "q":
                System.out.println("The program will now terminate.");
                System.exit(1);
            case "s":
                makeCurrent();
                break;
            case "t":
                listSort();
                break;
            default:
                System.out.println("Error. Please only enter an option from the menu.\n");
                break;
        } 
    } while(true);
}

Here is my stacktrace:

MENU DISPLAY

a Show all records

r Remove the current record

f Change the first name in the current record

l Change the last name in the current record

n Add a new record

d Add a deposit to the current record

w Make a withdrawal from the current record

q Quit

s Select a record from the record list to become the current record

Enter a command from the list above, or q to quit: n

Enter first name: Ada

Enter last name: Caswell

MENU DISPLAY

a Show all records

r Remove the current record

f Change the first name in the current record

l Change the last name in the current record

n Add a new record

d Add a deposit to the current record

w Make a withdrawal from the current record

q Quit

s Select a record from the record list to become the current record

Enter a command from the list above, or q to quit:

Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Scanner.java:1540)
at bank.main(bank.java:225)

I tried doing some research on the exception, and upon changing while(true) to while(input.hasNextLine()), that only seems to make things worse. Although I don't get the error anymore, input.hasNextLine fails to show the menu more than once after an option has been entered. How can I solve this?

MCaldera
  • 9
  • 3
  • Please post your stacktrace – Scary Wombat Mar 10 '16 at 01:21
  • That's not what a [stack trace](https://en.wikipedia.org/wiki/Stack_trace) is. Post the entire error output. (And in general in programming, *always* include the *entire* output any time you're asking for help. Don't abbreviate or paraphrase error messages.) – Chris Martin Mar 10 '16 at 02:06
  • Sorry for my lack of understanding, I have updated the post again with hopefully what is the stacktrace this time. – MCaldera Mar 10 '16 at 02:15

0 Answers0