私はそのように定義された要素のリストを持っています:
public List<Bullet> Bullets;
Bullet newBullet = new Bullet(0, 0, 0, 0, 0, 0, 0, 0);
画面上のボタンが押されると、次のように実行します。
newBullet.setProperties((int)(CannonCenterX + CannonEndX), (int)(CannonCenterY + CannonEndY), (int)(25*scaleX), (int)(25*scaleY), CannonEndX, CannonEndY, screenWidth, screenHeight);
Bullets.add(newBullet);
これにより、newBullet 要素のプロパティが変更され、そのコピーが箇条書きリストに追加されます。ただし、それを行うと、アプリケーションがクラッシュします。
ここのスレッド部分:
// 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
例外を生成し、プログラムを閉じます。既に生成された要素をリストに追加するとプログラムがクラッシュする理由がわかりません。どんな助けでも大歓迎です。
-ネイサン