Insersion Sort with Classes

Hello. I'm doing an insersion sort for an array of pet's in a store. Im running into two problems. My first problems is im trying to use the compareTo() to compare the name of each of these pets. Im running into a null pointer exception but dont know what to do about that or why im getting it. The second problem im running into is sorting the array of pets. I can switch the values from class to class, but wanna accually rearange the order of the classes in the array. .

These are my pet objects

Pet[] pet =new Pet[20];

this is when gets sent to each pet object when Abtnsubmit is pressed It sends it like this new Pet(String, double, int);

if(ae.getSource() == Abtnsubmit)

{

pet[count] =new Pet(Atxtname.getText(), Double.parseDouble(Atxtprice.getText()), Integer.parseInt(Atxtquanity.getText()));// send values from the test fields to create a new pet object

count++;// add to count

sort();

}

Ok here is the insersion sort code that i have been working with

for(int i=1; i<pet.length;i++)

{

int j = i;

double thing = pet[i].price;

while(j>0 && pet[j-1].price>thing)

{

pet[j] = pet[j-1];

j--;

}

pet[j] = thing;

}

I tried testing all this on a double at first to make sure it worked but relized that i would have to change all three valuse (string, double and int) if i wanted the classes to stay consistant with each other. But that would basicly be like a parallel array. Anyone got a solution? Thanks,

Cobbweb

[2078 byte] By [Cobbweba] at [2007-10-2 10:31:10]
# 1
correction in my insersion sort the part at the end should be this pet[j].price = thing;
Cobbweba at 2007-7-13 2:15:04 > top of Java-index,Other Topics,Algorithms...
# 2
Problem Solved .....
Cobbweba at 2007-7-13 2:15:04 > top of Java-index,Other Topics,Algorithms...