I'm trying to make a game that simulates chemical reactions. The problem is, after about five dust particles, the game crashes. Here's the code that moves particles:
public class Element extends Thread {
long temperature;
double x;
double y;
double XVel;
double YVel = 5;
ImageView iv;
Duration dur;
TranslateTransition tt = new TranslateTransition();
@Override
public void run() {
while (true) {
move();// calls the movement method repeatedly
try {
Thread.sleep(10);
} catch (InterruptedException ex) {
Logger.getLogger(Element.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
public void initialize() {
this.start();
}
/**
* @return the temperature
*/
public long getTemperature() {
return temperature;
}
public void checkCollisions() {
}
public void move() {
tt.setDuration(dur.millis(5));
tt.setByY(YVel);
tt.setCycleCount(1);
tt.setNode(iv);
tt.play();
}
}
Then, this exception comes up, and the game stops working:
java.lang.NullPointerException
at com.sun.scenario.animation.AbstractMasterTimer.timePulseImpl(AbstractMasterTimer.java:366)
at com.sun.scenario.animation.AbstractMasterTimer.timePulseImpl(AbstractMasterTimer.java:366)
at com.sun.scenario.animation.AbstractMasterTimer$MainLoop.run(AbstractMasterTimer.java:289)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:459)
at com.sun.javafx.tk.quantum.QuantumToolkit$9.run(QuantumToolkit.java:332)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:17)
at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:67)
at java.lang.Thread.run(Thread.java:744)
I don't know why a NullPointerException occurs, can anybody help me (I'm using JavaFX)? It would be very helpful if someone could tell me how this game does it (http://dan-ball.jp/en/javagame/dust/), for this game shows what i'm trying to accomplish. See for yourself.