I am trying to read in from a .txt file that has students' first names, last names and averages. I'm trying to read the data and store them in an array of objects, however, I am running into the following exception:
Exception in thread "main" java.lang.NullPointerException
at bubblesort.Bubblesort.readin(Bubblesort.java:34)
at bubblesort.Bubblesort.main(Bubblesort.java:49)
This is my code
package bubblesort;
import java.io.*;
import java.util.Scanner;
public class Bubblesort {
public class students{
public String name;
public String lastname;
public double average;
}
public static students[]readin(students[] studentinfo){
String info = "src/Files/numname.txt";
int count = 0;
String catcher = null;
try {
File InputFile = new File(info); //createsa new file input
Scanner Input = new Scanner(InputFile);
for (;count<25;count++){
studentinfo[count].name = Input.nextLine();
studentinfo[count].lastname = Input.nextLine();
studentinfo[count].average = Input.nextDouble();
catcher=Input.nextLine();
}
}
catch(IOException ex){
System.out.println("Error reading in file");
}
return studentinfo;
}
public static void main(String[] args) {
students[] studentinfo = new students[25];
readin(studentinfo);
}
}
If someone could please help me understand I would appreciate it a lot, thank you