Exception in thread "main" java.lang.NullPointerException
at Module.addStudentMark(Module.java:23)
at Module.main(Module.java:12)
This question is asked for getting student marks
Can someone help me to fix the error?
Because I cannot find the variable which cause runtime exception.
import java.util.Scanner;
class Module {
//limit size of array
final static int SIZE = 10;
public static void main(String args[]){
//Declaration
StudentMark studentMarkList[] = new StudentMark[SIZE];
int count = 0;
addStudentMark(studentMarkList);
}
public Module(){
StudentMark studentMarkList[] = new StudentMark[SIZE];
}
private static void addStudentMark(StudentMark studentMarkList[]){
Scanner sc = new Scanner(System.in);
for(int i = 0; i < SIZE; i++){
System.out.print("Enter Student " + (i + 1) + " ID: ");
studentMarkList[i].setId(sc.nextLine());
System.out.print("Enter Student " + (i + 1) + " marks: ");
studentMarkList[i].setMark(sc.nextInt());
}
}
}