Hi,
I have to sort customer names in a customer class i have created. Now, there is a method called getName() that basically returns the string name stored in an instance variable of the customer class.
This is a bubble sort method I have written. I really cant figure out why this throws a runtime null pointer exception at the IF statement which compares the strings. Please help.
[CODE=java]private Customer[] bubbleSort(Cust omer c[])
{
boolean swaped = true;
Customer temp;
if (c != null)
{
while(swaped)
{
swaped = false;
for (int i = 0; i < c.length - 1; i++)
{
if (c[i].getName().comp areTo(c[i + 1].getName()) > 0)
{
temp = c[i];
c[i] = c[i + 1];
c[i + 1] = temp;
swaped = true;
}
}
}
}
return c;
}[/CODE]
Thanks
I have to sort customer names in a customer class i have created. Now, there is a method called getName() that basically returns the string name stored in an instance variable of the customer class.
This is a bubble sort method I have written. I really cant figure out why this throws a runtime null pointer exception at the IF statement which compares the strings. Please help.
[CODE=java]private Customer[] bubbleSort(Cust omer c[])
{
boolean swaped = true;
Customer temp;
if (c != null)
{
while(swaped)
{
swaped = false;
for (int i = 0; i < c.length - 1; i++)
{
if (c[i].getName().comp areTo(c[i + 1].getName()) > 0)
{
temp = c[i];
c[i] = c[i + 1];
c[i + 1] = temp;
swaped = true;
}
}
}
}
return c;
}[/CODE]
Thanks
Comment