I have a list an element defined as such:
public List<Bullet> Bullets;
Bullet newBullet = new Bullet(0, 0, 0, 0, 0, 0, 0, 0);
When an onscreen button is pressed I run:
newBullet.setProperties((int)(CannonCenterX + CannonEndX), (int)(CannonCenterY + CannonEndY), (int)(25*scaleX), (int)(25*scaleY), CannonEndX, CannonEndY, screenWidth, screenHeight);
Bullets.add(newBullet);
That should change the properties of the newBullet element, and add a copy of it to the Bullet List. However once I do that the application crashes.
The threading part here:
// try locking the canvas for exclusive pixel editing on the surface
try {
canvas = this.surfaceHolder.lockCanvas();
synchronized (surfaceHolder) {
// update game state
this.gamePanel.update();
// draws the canvas on the panel
this.gamePanel.onDraw(canvas);
}
} finally {
// in case of an exception the surface is not left in
// an inconsistent state
if (canvas != null) {
surfaceHolder.unlockCanvasAndPost(canvas);
}
} // end finally
Generates an exception and the program closes. I have no idea why adding an already generated element to a list would crash the program. Any help is appreciated.
-Nathan
You need to create the list:
public List<Bullet> Bullets = new ArrayList<Bullet>();