everything in my code works fine till I get to the end and want to sort the list. the driver and the method both compile fine and the arraylist is present since it is used for all the other methods in the driver but when I go to sort the list I get an error.
this is the end section of the driver
intList.removeAt(position); //Line 31
System.out.println("Line 32: After removing the "
+ "element at position "
+ position
+ ", intList:"); //Line 32
intList.print(); //Line 33
System.out.println(); //Line 34
System.out.print("Line 35: Enter the search "
+ "item: "); //Line 35
System.out.flush(); //Line 36
num.setNum(Integer.parseInt(keyboard.readLine()));
System.out.println();
if(intList.seqSearch(num) != -1)
System.out.println("Line 40: Item found in "
+ "the list");
else
System.out.println("Line 42: Item not found");
System.out.print("List 43: The list temp: ");
intList.sortList(); //line 91 (problem line)
System.out.println();
}
}
here is the method:
public class OrderedArrayList extends UnorderedArrayList
{
public OrderedArrayList(int size)
{
super(size);
}
public OrderedArrayList()
{
super();
}
//Copy constructor
public OrderedArrayList(OrderedArrayList otherList)
{
super(otherList);
}
public void sortList()
{// start sort
list.print();
int min, i, j;
DataElement temp;
for ( i = 0; i < list.length; i++)
{// start for
// Assume first element is min
min = i;
for ( j = i + 1; j < list.length; j++)
{ // line 30 (other problem line)
if (list[j].compareTo (list[min])<0)
{
min = j;
}
}
if (min != i)
{
temp = list[i];
list[i] = list[min];
list[min] = temp;
}
System.out.println(list[i]);
}
}// end sort
}
and this is my output including the error:
----jGRASP exec: java -ea Example3_1
Line 7: Processing the integer list
Line 8: Enter 8 integers on the same line: 1 5 8 7 4 6 9 2
Line 16: The list you entered is: 1 5 8 7 4 6 9 2
Line 19: Enter the num to be deleted: 1
Line 24: After removing 1 the list is:
5 8 7 4 6 9 2
Line 27: Enter the position of the num to be deleted: 1
Line 32: After removing the element at position 1, intList:
5 7 4 6 9 2
Line 35: Enter the search item: 5
Line 40: Item found in the list
List 43: The list temp: Exception in thread "main" java.lang.NullPointerException
at OrderedArrayList.sortList(OrderedArrayList.java:30)
at Example3_1.main(Example3_1.java:91)
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.