0

我有一个这样定义的元素列表:

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   

产生异常并且程序关闭。我不知道为什么将已经生成的元素添加到列表中会使程序崩溃。任何帮助表示赞赏。

-内森

4

1 回答 1

1

您需要创建列表:

public List<Bullet> Bullets = new ArrayList<Bullet>();
于 2012-03-16T00:40:58.553 回答