Frogger NullPointerException
in
Programming Questions
•
9 months ago
Hi!
I'm fairly new to programming but i'm getting a handle on it. My problem is that im getting a NullPointerException error and have no idea why. Any help would be greatly appreciated! Thnks!
I'm doing a frogger kind of game. The Rectangles would be the cars moving.
Here's my code:
1st Tab:
Rectangle[] rectangle;
Frog frog;
void setup() {
size(600, 400);
Rectangle[] rectangle = new Rectangle[8];
for (int i = 1; i < 8; i++)
{
for (int k = 45; k < 150; k = k+15)
{
int _centerX = (int) random(0, width);
int _centerY = ((i-1)*15)+k;
int _cHeight = 2*GAP;
int _cWidth = (int) random(40, 100);
rectangle[i] = new Rectangle(_centerX, _centerY, _cWidth, _cHeight);
}
}
for (int i=0; i < rectangle.length; i++)
{
rectangle[i].display();
}
}
2nd Tab:
class Rectangle {
int cWidth, cHeight;
int centerX, centerY;
float speed;
int shade;
color col;
Rectangle(int _centerX, int _centerY, int _cWidth, int _cHeight )
{
centerX = _centerX;
centerY = _centerY;
cWidth = _cWidth;
cHeight = _cHeight;
col = color(random(255), random(255), random(255));
}
void display()
{
noStroke();
fill(col);
rect(centerX, centerY, cWidth, cHeight);
}
}
1