0
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());
         }
     }
 }
Poi
  • 1
  • 1
  • 1
    Does this answer your question? [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Joshua Burt Jul 02 '20 at 12:32
  • I still cannot find out my problem through the link – Poi Jul 02 '20 at 12:37
  • 2
    Here lies the actual the problem: [NullPointerException when Creating an Array of objects](https://stackoverflow.com/questions/1922677/nullpointerexception-when-creating-an-array-of-objects). You're creating an array, but don't fill it with values – QBrute Jul 02 '20 at 12:53

0 Answers0