I'm trying to call the following method of my Asteroid class:
Quote:void explode() {
// some nasty magic numbers in here...
if(mass >= 3) {
mass /= 6;
w *= 0.75;
h *= 0.75;
vx = random(2)-1;
vy = random(2)-1;
float vx1 = -vx + (random(0.4)-0.2);
float vy1 = -vy + (random(0.4)-0.2);
space.asteroids.add(new Asteroid(x,y,w,h,mass,vx1,vy1,space));
}
else {
removeAsteroid();
if(space.asteroids.size() == 0){
println("level complete");
}
}
}
...but the highlighted line is causing it to throw the following error:
Quote:java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav
a:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at processing.core.PApplet$RegisteredMethods.handle(PApplet.java:723)
at processing.core.PApplet$RegisteredMethods.handle(PApplet.java:716)
at processing.core.PApplet.handleDraw(PApplet.java:1439)
at processing.core.PApplet.run(PApplet.java:1327)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.get(ArrayList.java:322)
at asteroids02$Space.draw(asteroids02.java:277)
... 8 more
Either I'm trying to do something 'the wrong way'; or I've got some trivial bug... But I'm not too sure how to debug it. If I've understood correctly the problem occurs when it tries to instantiate the new Object, but rather than showing that error this error is triggered to 'catch' it. The weird thing is everything carries on running as it should...
Can I use try/catch in some way to display the invocation error?