View Single Post
  #8 (permalink)  
Old 11-05-2007, 08:56 PM
hardwired hardwired is offline
Senior Member
 
Join Date: Jul 2007
Posts: 1,266
hardwired is on a distinguished road
Code:
public class ButtonHandler implements ActionListener { ... if(button == add) { // Problem was here: incrementing num_students too early // which skips over the array element at index = 0. // num_students++; stu[num_students].getData(); num_students++; }
So the first element in the stu array (at index = 0) was skipped and you were
initializing the second element (index = 1). This caused trouble in the loop
of the getCopy method:
Code:
for(int j = 0; j < stu.length; j++) { if(stu[j].getName() == null) break; count++; }
which broke out at the first element (j = 0) because it had been skipped.
So getCopy returned a zero-length array to the sortByGPA method.

In conjunction with this you could alter the test method to be able
to add more elements to the array:
Code:
private void test() { // remove the add.setEnabled line ... stu[2].addCourse(new Course("ES", 220, 5, "A")); num_students = 3; }
Reply With Quote