I wrote a java to test a insertion sort for strings, but it comes up with error saying "java.lang.NullPointerException:
import java.util.Arrays;
public class SortTest
{
private String[] array;
final int size = 5;
public void sort()
{
String insert;
array = new String[size];
for ( int next = 1; next < array.length; next++ )
{
insert = array[next];
int moveItem = next;
while (moveItem > 0 && array[moveItem -1].compareTo(insert) > 0)
{
array[moveItem] = array[moveItem -1];
moveItem--;
}
array[moveItem] = insert;
}
}
public static void main (String[] args)
{
SortTest stringSort = new SortTest();
String array[] = {"aaa", "ccc", "eee", "zzz", "bbb"};
stringSort.sort();
System.out.println( stringSort );
}
}
I followed most of the codes from textbook and I really can't find where the problems are, please give me some help! Any help is appreciated!