I don't know why I keep getting an InputMismatchException :/ It highlights when I call the load() method.

Thanks

import java.util.*;
import java.io.*;
public class GradeManager {
	
	private ArrayList <Student> StudentGrades;
	
	public GradeManager(){
		
		StudentGrades=new ArrayList<Student>();
		load();
		
	}
		
	public void load(){
		
		Scanner fileIn=null;
		try{
			
			fileIn=new Scanner(new File("grades.txt"));
		}catch(FileNotFoundException e){
			
			System.out.print("Cannot find file.");
			System.exit(-1);
		}
		
		while(fileIn.hasNextLine()){
			
			//fileIn.nextLine();
			StudentGrades.add(new Student(fileIn.nextLine(), fileIn.nextInt()));
		}
	}
	
	
	public static void main(String[] args){
		
		GradeManager g=new GradeManager();
		
	}

	
}

This is the format of the file:

Name
Grade(Integer)
...

The error is probably because the call to nextInt on line 29 does not advance the read pointer to the next line. Try moving line 28 to after line 29 and take the comment marker off. If this doesn't fix the problem, please post your student class and attach the data file you're trying to read.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.