我正在制作一个安卓游戏,它会在屏幕顶部以一定的间隔生成敌人的精灵。没有语法错误,但是当我运行游戏时它会因为这个函数而崩溃:
public void updateEnemies() {
if (numEnemiesCreated == numVisibleEnemies) {
if (timeLastCreatedEnemy + 1000 < System.currentTimeMillis()) {
timeLastCreatedEnemy = System.currentTimeMillis();
boolean createdNewEnemy = false;
for (int i = 0; i < this.numVisibleEnemies; i++) {
if (createdNewEnemy == false) {
if (holderEnemy[i].isDisposed()) {
this.generateNewEnemy(i);
createdNewEnemy = true;
}
}
}
}
for(int i = 0; i<numVisibleEnemies; i++){
if(!holderEnemy[i].isDisposed()){
holderEnemy[i].move();
}
}
} else {
holderEnemy[numEnemiesCreated] = new Enemy(context, 0, 0);
numEnemiesCreated++;
}
}
我已经尝试了一切,我就是无法让它工作!这是我的日志猫崩溃报告:
05-25 18:49:13.031: W/dalvikvm(6736): threadid=9: thread exiting with uncaught exception (group=0x40015578)
05-25 18:49:13.035: E/AndroidRuntime(6736): FATAL EXCEPTION: Thread-10
05-25 18:49:13.035: E/AndroidRuntime(6736): java.lang.NullPointerException
05-25 18:49:13.035: E/AndroidRuntime(6736): at com.jlennon.gametest.EnemySpawn.updateEnemies(EnemySpawn.java:49)
05-25 18:49:13.035: E/AndroidRuntime(6736): at com.jlennon.gametest.MainGamePanel$AnimationThread.update(MainGamePanel.java:94)
05-25 18:49:13.035: E/AndroidRuntime(6736): at com.jlennon.gametest.MainGamePanel$AnimationThread.run(MainGamePanel.java:61)