I followed this code and for some reason its showing the error in the image. i cant figure out whats wrong, please help!
Scanner sc = new Scanner(System.in);
ArrayList <Student> students = new ArrayList<Student>();
ArrayList <Student> courses = new ArrayList<Student>();
// Method to read the file contents and stores it in
// instance arrays
void readStudents()
{
// Scanner class object declared
Scanner readStuF = null;
// try block begins
try
{
// Opens the file for reading
readStuF = new Scanner(new File("student.txt"));
// Loops till end of the file to read records
while(readStuF.hasNextLine())
{
String stu = readStuF.nextLine();
String []eachStu = stu.split(" ");
students.add(new Student(eachStu[0], eachStu[1],
eachStu[2], Long.parseLong(eachStu[3]),
Integer.parseInt(eachStu[4]), Integer.parseInt(eachStu[5]),
Integer.parseInt(eachStu[6])));
}// End of while loop
}// End of try block
// Catch block to handle file not found exception
catch(FileNotFoundException fe)
{
System.out.println("\n ERROR: Unable to open the file for reading.");
}// End of catch block
// Close the file
readStuF.close();
}// End of method
I followed this code and for some reason its showing the error in the image. i cant figure out whats wrong, please help!
Step by step
Solved in 2 steps