linked list problem

Hi, I have this program, where a method should go through a linked list, and when reached the end, start over again, but I keep getting a NullPointerException... Take a look at this ;)

publicstaticvoid calc(){

double rand = 0;

double day_rand = Math.random();

day_rand = Math.round(day_rand);

try{

Thread.sleep(100);

}catch(Exception e){}

if (current.next ==null || current ==null){

current = head;

}

double increase = 0.0;

while (current !=null && current.next !=null &&

current.active ==true){

rand = Math.random();

increase = ((current.speedMod * current.exp * rand )

+ day_rand );

if (increase > 1){

current.progress++;

}

System.out.print("Horse " + current.nr +": ");

for (int i = 0; i < current.progress; i++){

System.out.print("=");

}

System.out.print("\n");

check();

current = current.next;

}

}

[2074 byte] By [tomclancya] at [2007-10-1 0:59:52]
# 1
What line?
Adeodatusa at 2007-7-8 1:19:04 > top of Java-index,Security,Event Handling...
# 2

Acctualy, it points to the

check();

line.. and check() is:

public static void check() {

if ((current.progress > 50) && (current.active = true)) {

refresh();

if (finish == 1) {

current.first = true;

current.exp += 4;

System.out.println("We have a winner");

}

else if (finish == 2) {

current.second = true;

current.exp += 3;

}

else if (finish == 3) {

current.third = true;

current.exp += 2;

}

else if (finish == 4) {

current.fourth = true;

current.exp += 1;

}

current.active = false;

save();

}

if (current.fourth == true) { //And compiler points here as well... I dont get it...

System.out.println("Race over." + finish);

WIN = true;

}

}

tomclancya at 2007-7-8 1:19:04 > top of Java-index,Security,Event Handling...
# 3
Maybe there is another way to systematic do some operations on objects? Maybe give each object an ID, and use that to refer to it, and then manipulate it? This linked list is not so easy...
tomclancya at 2007-7-8 1:19:04 > top of Java-index,Security,Event Handling...
# 4

> Acctualy, it points to the

>

> check();

When you get an exception you also get a stack trace with the EXACT line. Why don't you point that LINE out so people don't have to guess.

But I've spotted on error in check

if ((current.progress > 50) && (current.active = true))

Here current.active is ASSIGNED true. I hope that's not your intention.

uj_a at 2007-7-8 1:19:04 > top of Java-index,Security,Event Handling...
# 5
yeah, you got that error right, thanks ;)the compiler points to theif (current.fourth == true)line... the code seems ok, and since it is a NullPointerException, it has to be something with the linked list?
tomclancya at 2007-7-8 1:19:04 > top of Java-index,Security,Event Handling...
# 6
Post the exact error message, and tell us which line it's talking about.
jverda at 2007-7-8 1:19:04 > top of Java-index,Security,Event Handling...
# 7
The stacktrace, rather. Not just "NullPointerException."
jverda at 2007-7-8 1:19:04 > top of Java-index,Security,Event Handling...
# 8
At a guess, though, current is null.Print out current right before the line that gives NPE.Then when it's null, even though you're sure it can't be, print it out at various previous steps until you find your mistake.
jverda at 2007-7-8 1:19:04 > top of Java-index,Security,Event Handling...