I am trying to read input from the command line and put it in an ArrayList. I do it multiple times in the program but one time is throws the NoSuchElementException. What am I doing wrong?
public static ArrayList<Double> getInfoTwo ()
{
ArrayList<Double> infoListTwo = new ArrayList<Double>();
Scanner in = new Scanner(System.in);
System.out.println("Please enter your total hours: ");
infoListTwo.add(in.nextDouble());
in.close();
return infoListTwo;
}
it looks like your in.NextDouble() is throwing this. As per the Javadoc ( http://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#nextDouble() )
This is because there is no data for the scanner to read. Try surrounding that call with in.hasNextDouble()