Question: Could you help me with the method below, it keeps resulting in a null point exception for the circularly linked list musicalChairs? I've pasted my

Could you help me with the method below, it keeps resulting in a null point exception for the circularly linked list musicalChairs?

I've pasted my code, as well as the instructions for the method below:

My code:

public void insertMusicalChairs () {

musicalChairs = new SNode();

int numRows = studentsSitting.length;

int numCols = studentsSitting[0].length;

for (int i = 0; i < numRows; i++) {

for (int j = 0; j < numCols; j++) {

if (studentsSitting[i][j] != null) {

musicalChairs.add(studentsSitting[i][j]); // insert student into musical chairs list

musicalChairs = musicalChairs.getNext();

studentsSitting[i][j] = null; // clear the seat where the student was sitting

seatingLocation[i][j] = true; // update seating chart to reflect available seat

}

}

}

}

The instructions:

insertMusicalChairs

This method represents students preparing to start musical chairs! Assume that the students are instudentsSitting.

  • Imagine this as a circle of chairs.
  • This method will take students from thestudentsSittingarray and add them to themusicalChairscircular linked list.
  • Students are to be inserted at the end of the linked list by traversing row-wise, then column-wise in the studentsSitting array.
  • REMEMBER: the pointer to a circular linked list points to the LAST item in the list, and that item points to the front.

These are the comments:

/**

* Traverses studentsSitting row-wise (starting at row 0) removing a seated

* student and adding that student to the end of the musicalChairs list.

*

* row-wise: starts at index [0][0] traverses the entire first row and then moves

* into second row.

*/

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!