2012-03-16 94 views
0

我有一個列表定義爲這樣的元件:Android應用程序崩潰時元添加到列表

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 

產生異常,程序關閉。我不知道爲什麼將一個已經生成的元素添加到列表中會導致程序崩潰。任何幫助表示讚賞。

-Nathan

+0

是它摔碎在哪一行?什麼是例外? – dldnh 2012-03-16 00:39:53

回答

1

您需要創建列表:

public List<Bullet> Bullets = new ArrayList<Bullet>(); 
+0

太棒了!謝謝你的幫助! – 2012-03-16 01:06:31

相關問題