I am not sure why I am getting this error. When I run my program I get this
java.util.NoSuchElementException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextDouble(Unknown Source)
I am only running one scanner and it's closed after this while loop. I was curious if anyone can give me a hint on how I should five it. Here is some of the code. I also made a comment on line 27 since that is where the error is occurring at i think.
try {
File file = new File("src/text.txt");
File finalGrades = new File("src/nextText.txt");
PrintWriter output = new PrintWriter(finalGrades);
File finalGradesReport = new File("src/nextTextReport.txt");
PrintWriter output2 = new PrintWriter(finalGradesReport);
Scanner input = new Scanner(file);
double totalPointsAvailable = input.nextDouble();
double homeworkWeight = input.nextDouble() / totalPointsAvailable;
double projectsWeight = input.nextDouble() / totalPointsAvailable;
double firstExamWeight = input.nextDouble() / totalPointsAvailable;
double secondExamWeight = input.nextDouble() / totalPointsAvailable;
double finalExamWeight = input.nextDouble() / totalPointsAvailable;
int numA = 0, numB = 0, numC = 0, numD = 0, numF = 0, numStudents = 0;
double totalPercGrades = 0, averageGrades = 0;
while (input.hasNext()) {
double hw = input.nextDouble() * homeworkWeight;
double pw = input.nextDouble() * projectsWeight; //line 27
double firstEx = input.nextDouble() * firstExamWeight;
double secondEx = input.nextDouble() * secondExamWeight;
double finalEx = input.nextDouble() * finalExamWeight;