NullPointerException
in
Programming Questions
•
2 years ago
Hi, another newbie with a simple question.
I'm getting a NullPointerException at the following line, and I can't quite figure out what's wrong.
I'm getting a NullPointerException at the following line, and I can't quite figure out what's wrong.
- Ball myBall;
void setup() {
size(200,200);
smooth();
background(255);
Ball myBall = new Ball(width/2,height/2,0,0,0,-.098,10);
}
void draw() {
myBall.update();
myBall.display();
}
class Ball {
PVector loc;
PVector vel;
PVector acc;
float dia;
Ball(float tempx, float tempy, float tempvx, float tempvy, float tempax, float tempay, float tempdia) {
loc = new PVector(tempx, tempy);
vel = new PVector(tempvx, tempvy);
acc = new PVector(tempax, tempay);
dia = tempdia;
}
void update() {
vel.add(acc);
loc.add(vel);
}
void display() {
fill(0);
stroke(0);
ellipse(loc.x,loc.y,dia,dia);
}
}
1