View Single Post
Old Dec 1st, 2006, 9:58 PM   #2
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 843
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Grades[] data = new Grades[NUM_PERSON];
This code creates an array capable of storing NUM_PERSON Grades objects. By default, each index is initialized to null.

data[index].setGrades(firstName, lastName, classNum, grade);
You are attempting to call the method setGrades on null, hence the NullPointerException.

One solution is to initialize each index of data to a new instance of Grades in the GradeReader class' constructor, which will be called when a new instance of GradeReader is created:
public class GradeReader {

      public GradeReader() {
            for (int i = 0; i < NUM_PERSON; i++)
                  data[i] = new Grades();
      }

...
titaniumdecoy is offline   Reply With Quote