I'm getting a null pointer exception at line
if(names[j].compareTo(names[j+1]) > 0)
and I can't figure out why. It might have something to do with the initialization but I really don't know what it could be
public static void item3(Profitable[] movies, Scanner input) {
int j;
boolean flag = true;
String temp;
String search;
int low = 0;
int high;
int mid;
String[] names = new String[6];
for(int i = 0; i < 5; i++) {
names[i] = ((Movie)movies[i]).getTitle();
}
high = names.length - 1;
mid = (low + high) / 2;
while(flag)
{
flag = false;
for(j = 0; j < names.length - 1; j++)
{
if(names[j].compareTo(names[j+1]) > 0) {
temp = names[j];
names[j] = names[j+1];
names[j+1] = temp;
flag = true;
}
}
}
System.out.print("Enter your search term: ");
search = input.nextLine();
}