I'm learning about BufferedReaders and a few other classes and am making a small program that takes a text file with information about courses I've taken and calculates my GPA. Here's what I have so far:
import java.util.ArrayList;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
class GradeFormatter {
public static ArrayList<String[]> courses;
public static double unitsAttempted;
public static double unitsPassed;
public static double gradePoints;
public static double gpa;
public static void main(String[] args) {
try {
FileReader fileReader = new FileReader("grades.txt");
BufferedReader reader = new BufferedReader(fileReader);
while (true) {
String line = reader.readLine();
if (line == null) {
break;
} else {
processLine(line);
}
}
reader.close();
} catch (IOException e) {
System.out.println("File does not exist.");
}
}
public static void processLine(String line) {
String[] newCourse = line.split("\\t");
courses.add(newCourse);
}
}
I'm getting the following output when I try to run the program:
Exception in thread "main" java.lang.NullPointerException
at GradeFormatter.processLine(GradeFormatter.java:34)
at GradeFormatter.main(GradeFormatter.java:23)
Could anyone help me out with why I'm getting this null pointer exception? I cannot seem to figure out where it's coming from.