In the code below I try to get the grade of all my subjects. I get the input via a for loop. But I'm supposed to store the grade ("C" for example) in the grade array but I get a NullPointerException. I don't understand what's wrong with my code since I thought it was good to go. Also, ignore the names of the subjects since they are in Swedish.
public class Defan{
Scanner sc = new Scanner(System.in);
String grade[];
String gradeName[] = {"Svenska1", "Svenska2", "Svenska3", "Engelska5", "Engelska 6",
"Mattematik 1c", "Mattematik 2c", "Mattematik 3c", "Mattematik 4", "Idrott", "Samhälle", "Religion",
"Historia", "Biologi1", "Biologi2", "Fysik1", "Fysik2", "Kemi1", "Kemi2", "Franska3", "Franska4", "Körsång1", "Körsång2"
, "Gymnasiearbete"};
public void getInput(){
for(int i = 0; i <= gradeName.length; i++){
System.out.println("Enter grade for " + gradeName[i] + ": ");
grade[i] = sc.nextLine();
}
}