0

Ok so the relevant part of code:

 public static void assignClassBig(Schedule[] bigSchedule, Student student, int classA, ArrayList<Integer>[] classesXperiods, ArrayList<Integer> classes, int period) {
    int id = student.getID();
    int classB = classes.get(classA);
    int periodA = classesXperiods[classB].get(period) + 1;
    bigSchedule[id].assignClass(classB, periodA);
  }

bigSchedule is an array of the object Schedule which contains a student object and an array which acts as the schedule, each entry in the array is a period etc.

Now in my main method I made the array:

Schedule[] bigSchedule = new Schedule[nOstudents];

However, when I try to access one of the Schedule objects in it say Schedule[0] it is a null value. How do i initialize the schedules or whatever it is called so I can use it.

1 Answer 1

3

You have to explicitly set it:

for (int i = 0; i < nOstudents; i++) {
  bigSchedule[i] = new Schedule(); // or however you construct Schedules
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.