Hey, I’m really new to java..so I'm really not sure what some of the errors mean , when I run this program it reads data from the file and all but I can’t get it store new data in a new file, the file “exo” does get created though.
Here’s what the program looks like

import java.io.*;
import java.util.*;

public class studentGrade{

    public static void main(String[] args) 
        throws FileNotFoundException
            {//start of main

            try{

        Scanner inFile=new Scanner(new FileReader("studentmarks.txt"));     

        double test;
        double average;
        String firstName;
        String lastName;

        firstName=inFile.next();
        lastName=inFile.next();

        System.out.println(firstName+" "+lastName);
        PrintWriter outFile=new PrintWriter("exo.txt");
        outFile.println("Student Name: "+firstName+" " +lastName);



        double marks[]= new double[7];

            System.out.print("Test scores : ");
        for(int x=0;x<marks.length;x++){

            marks[x]=inFile.nextDouble();
            System.out.print(marks[x]+ ", ");
            outFile.println("marks "+x+" marks[x] ");
        }

        inFile.close();
        outFile.close();

        }
    catch(IOException exc){
            System.out.println("File not found \n"+exc);
        }   
    }//end of main
}

And this is the message I get,

--------------------Configuration: <Default>--------------------
Don Johnson
Test scores : 87.5, 89.0, 65.0, 37.5, 98.0, Exception in thread "main" java.util.NoSuchElementException
    at java.util.Scanner.throwFor(Scanner.java:838)
    at java.util.Scanner.next(Scanner.java:1461)
    at java.util.Scanner.nextDouble(Scanner.java:2387)
    at studentGrade.main(studentGrade.java:33)

Process completed.

Can someone please tell me how to correct it, and where I went wrong.
Thanx most awfully , I really need some help.

Edited 3 Years Ago by Nick Evan: Fixed formatting

Is the problem in this line??

marks[x]=inFile.nextDouble();

if so, how can I correct it??

yes James , anyway guyz thanx for the help.
I solved the problem by puttilg a while loop instead of a for loop!

        while(inFile.hasNext()&&( x <7)){


                marks[x]=inFile.nextDouble();
                System.out.print(marks[x]+ ", ");
                outFile.println("marks "+x+" "+ marks[x] );
                x++;
            }

    :)

Edited 3 Years Ago by Nick Evan: Fixed formatting

This question has already been answered. Start a new discussion instead.