0

I am passing a parameter

 public void addStudent(String studentName) 
    {   
      if (studentName != null) 
    {    int[] array = new int[NUM_QUIZZES];    
    for (int i = 0; i < array.length; i++) 
    {     
    array[i] = MIN_GRADE;    
    }    
    quizMarks.put(formatName(studentName), array);  
     } 
       }  
> new student, marks set to 0  
/**   
* returns the quiz marks for a given student   
* @param student   
* @return the array of quiz marks for this student  
*/ public int[] getQuizzes(String student) 
    {   
    int[] array = quizMarks.get(student);   
    if (student != null) 
    {    
    for (int arrays : array)
    {     System.out.println(arrays);    
    }
       }   return array; 
  }  

I want to get the marks displayed, but it gives me Exception in thread "main" java.lang.NullPointerException at StudentDatabase.getQuizzes(StudentDatabase.java:68) : line 68: for (int arrays : array)

CBroe
  • 91,630
  • 14
  • 92
  • 150
LZed
  • 1
  • 2
    _Please_, for the love of Gosling, format your code. – Mike G Apr 28 '16 at 21:16
  • 1
    Perhaps you should be checking that `array` is not null (the return from `quizMarks.get()`, not `student`? Plus, this isn't a proper example for this site - e.g., `addStudent` is not necessary and there's no `main()` to execute - see [how to create a minimal complete and verifiable example](http://stackoverflow.com/help/mcve). – davidbak Apr 28 '16 at 21:18
  • When adding a student, the key is `formatName(studentName)`. When getting a student, the key is `student`. – JB Nizet Apr 28 '16 at 21:19

0 Answers0