Erro na execução - Aplicação do Livro GAMES com JAVA JONATHAN hARBOUR

1 resposta
G

Alguem pode me ajudar, estou recebendo a msg ai na execução do metodo abaixo

Exception in thread “Thread-3” java.lang.NullPointerException

at Asteroids.updateBullets(Asteroids.java:251)

at Asteroids.gameUpdate(Asteroids.java:214)

at Asteroids.run(Asteroids.java:188)

at java.lang.Thread.run(Thread.java:722)

/*************************************************************************
* update the bullets based on velocity
************************************************************************/
public void updateBullets() {

//move each of the bullets
    for (int n = 0; n < BULLETS; n++) {
        
        //is this bullet being used?
        if (bullet[n].isAlive()) {

            //update bullet's X position
            bullet[n].incX(bullet[n].getVelX());

            //bullet disappears at left/right edge
            if (bullet[n].getX() < 0 ||
                    bullet[n].getX() > getSize().width)
            {
                bullet[n].setAlive(false);
            }

            //update bullet's Y position
            bullet[n].incY(bullet[n].getVelY());

            //bullet disappears at top/bottom edge
            if (bullet[n].getY() < 0 ||
                    bullet[n].getY() > getSize().height)
            {
                bullet[n].setAlive(false);
            }

        }
    }
}

1 Resposta

GusMcCart

Você está inicializando seus objetos antes de utilizar??? Qual é a linha 251 da classe bullet? Posta o código entre as tags code.

Criado 10 de agosto de 2012
Ultima resposta 10 de ago. de 2012
Respostas 1
Participantes 2