My code's not working and I don't know why. I'm trying to read numerical values from a file and saving all instances where a letter is entered instead of a number to a string to be referenced as an error at a later point on in the code. However, there's an error and like I've stated before, I don't know what caused it.
This is the error that returns.public static void validateData() throws IOException{ File myfile = new File("gradeInput.txt"); Scanner inputFile = new Scanner(myfile); for (int i=0; i<33; i++){ if(inputFile.hasNextDouble()){ double d = inputFile.nextDouble(); if (d<0||d>99999){ System.out.println("Not a valid ID."); System.exit(0); } } else{ String s = inputFile.next(); } String extraCredit = inputFile.next(); String toBeDoubleOne = extraCredit; Double fromStringOne = new Double(toBeDoubleOne); if (fromStringOne<0||fromStringOne>5){ double error1 = fromStringOne; } String grade = inputFile.next(); String toBeDoubleTwo = grade; Double fromStringTwo = new Double(toBeDoubleTwo); if (fromStringTwo<0||fromStringTwo>100.00){ double error2 = fromStringTwo; } } inputFile.close(); }
Thanks in advance!Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:838) at java.util.Scanner.next(Scanner.java:1347) at Paniagua_Grading.validateData(Paniagua_Grading.java:29) at Paniagua_Grading.main(Paniagua_Grading.java:6)