nullpointerexception help?
in
Programming Questions
•
7 months ago
PImage space;
PImage evil;
Enemy a1;
SpaceShip b1;
ArrayList<Enemy>bad = new ArrayList();
ArrayList<SpaceShip>bullets= new ArrayList();
void setup()
{
background(255);
size(1000, 1000);
evil = loadImage("evil.png");
for (int i = 0; i< 1000; i=i+145)
{
image(evil,i,70);
}
}
void mousePressed()
{
bullets.add(new SpaceShip(mouseX+9,mouseY+210,5));
}
void draw()
{
background(255);
if(key == 'w')
{ space = loadImage("spaceship2.jpg");
image(space,mouseX-85,mouseY-45);
}
if(key=='a')
{
space = loadImage("3.gif");
image(space,mouseX-135,mouseY-155);
}
if(key=='d')
{space = loadImage("2.gif");
image(space,mouseX-155,mouseY-105);}
for(int i=0;i<bullets.size();i++)
{
SpaceShip b=bullets.get(i);
}
b1.display();
a1.display();
}
public class Enemy
{
private int x;
private int y;
public Enemy(int tx, int ty)
{
x=tx;
y=ty;
}
public void display()
{
image(evil, x, y);
}
}
class SpaceShip
{
private int xPos;
private int yPos;
private int speed;
private int r;
private int g;
private int b;
private boolean shot;
public SpaceShip(int x,int y,int sp)
{
xPos =x-9;
yPos =y-300;
speed =35;
r= 28;
g=166;
b =177;
shot =false;
}
public void setKST()
{
shot = true;
}
public void setKSF()
{
shot = false;
}
public void display()
{
fill(r,g,b);
rect(xPos,yPos,7,50);
yPos-=speed;
}
}
the a1.display and b1.display gets highlighted when i click play and says nullpointerexception
1