Here are some excerpts of my code...
import java.util.*; import java.io.*; public class Driver2{ private static String fileName; private static CLLOfRiders list = new CLLOfRiders(); private static Scanner input = new Scanner(System.in); public static void main (String args[]) { System.out.println("Welcome to Project 2."); System.out.println("What is the name of the data file?"); fileName = input.nextLine(); openFile(fileName); commands(); //ERROR HERE!!!!!!!!!!!! writeFile(fileName); input.close(); } .... public static void commands() { boolean loop = true; String command; while (loop == true) { System.out.println("\nNext command"); command = input.nextLine(); //ERROR HERE!!!!!!!!!!!!!!! if (command.equals("add rider")) { System.out.println("Name"); String name = input.nextLine(); addRider(name); } ... } }
I'm getting this error from Eclipse.
The lines where the error occurs are in commented with "ERROR HERE". Why am I getting this exception? I rewrote command() in a test program and, normally, the Scanner waits for the user to input data. Not here, though?java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Unknown Source)
at Driver2.commands(Driver2.java:64)
at Driver2.main(Driver2.java:21)