nullpointer exception error of array object
I hae declared , initialised object array but still i get the uncaught nullpointer exception error in java.lang
here is the code :
public class GameScreen extends GameCanvas implements Runnable, CommandListener {
// statements
public int bulletindex =0;
BulletSprite bulletsprite[ ] = new BulletSprite[100];
// statements
public GameScreen(Eliminator midlet,Settings settings,Score score) throws Exception {
//statements
for(int i=0;i<bulletsprite.length;i++)
{
bulletsprite = new BulletSprite(imagebullet);
}
//statements
} // GameScreen constructor ends here
// statements
public void tick() {
//statements
if ((keyStates & FIRE_PRESSED) != 0) {
Sprite enemybullet = bulletsprite[bulletindex].fire(bulletimage,enemy.x,enemy.y);
}
//statements
} // end of tick()
I have BulletSprite.java file where the following code exists.
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
public class BulletSprite extends Sprite {
private int dx ,dy;
public BulletSprite(Image image) throws Exception
{
super(image);
}
private void MoveBullet()
{
move(dx,dy);
}
public Sprite fire(Image bullets,int x , int y)
{
Sprite bullet = new Sprite(bullets,2,2);
bullet.setFrame(0);
bullet.setPosition(x - bullet.getWidth() / 2 + this.getWidth() / 2, y);
return bullet;
}
}
If I comment out the line for fire , no error comes , but with that line error is there.
i mean this line : Sprite enemybullet = bulletsprite[bulletindex].fire(bulletimage,enemy.x,enemy.y);
What am I doing wrong ?
Thanks in advance for any help.
Regards,
Doka>

