Exception in thread “main” java.util.NoSuchElementException: No line found – Using scanner input [duplicate]

The problem is you are closing System.in (Scanner.close() closes the underlying stream). Once you do that, it stays closed, and is unavailable for input. You don’t normally want to do that with standard input:

String searchedNode;
Scanner in = new Scanner(System.in);
System.out.println("Enter the name you would like to remove from the list: ");
searchedNode = in.nextLine();
// in.close(); // <-- don't close standard input!

Also, for future reference, you should try to create more minimal test cases. It will help you debug and also remove a lot of noise from your questions. 🙂

Leave a Comment