I am writing a program that stores a student's name, student number and his grade for a course in a textfile.
Now I am writing the method for accessing the grade of the student. The method gets the desired student number as input. In the code below I get the error
java.lang.ArrayIndexOutOfBoundsException, for the lines:
System.out.println(studentFile [1]); and the if statement.
I think I am accessing the element in the wrong way but I am not 100% sure. The rest of methods work like a breeze.
public  static void getGradeOfStudentNumber(String studentNumberForGrade){
        try
        {
        String line;
        BufferedReader br = new BufferedReader(new
        FileReader("StudentArchive.txt"));
        while((line = br.readLine())!= null)
        {
        String[] studentFile = line.split(",");
        System.out.println(Arrays.toString(studentFile));
        System.out.println(studentFile [1]);
         /*if ((studentFile[1]).equals(studentNumberForGrade))
        {
         String grade = studentFile[2];
         System.out.println("the student's grade is "+ grade);
        }*/
        }
        br.close();
        }
        catch (IOException ex)
        {
        System.out.println("The file does not exist");
        }
    }       
}
 
     
    