Nullpointerexeption with an arraylist
in
Programming Questions
•
6 months ago
Hello I'm starting with oriented object programming and i'm getting a nullpointerexeption when I try to compile the code.
It's supposed to create a ball at the position where I'm clicking and the balls are moving around and bump on the sides.
here is the code :
It's supposed to create a ball at the position where I'm clicking and the balls are moving around and bump on the sides.
here is the code :
class balle{
float x;
float y;
float deplx;
float deply;
balle(){
x= mouseX;
y= mouseY;
deplx = random(0,3);
deply = random(0,3);
}
void show() {
ellipse(x,y,20,20);
}
void rebond() {
x += deplx;
y += deply;
if ( y > 395) {
deply = -deply ;
}
if (y < 5) {
deply = -deply ;
}
if ( x > 395) {
deplx = -deplx ;
}
if (x < 5) {
deplx = -deplx ;
}
}
}
ArrayList balles;
balle ball;
void setup() {
size(400,400);
ball = new balle();
}
void mouseClicked() {
balles.add(new balle());
}
void nettoyer() {
size(400,400);
background(0) ;
}
void draw() {
nettoyer();
for (int i = 0; i < balles.size()-1; i++ ) { // here is when it's highlighted
balle balle = (balle) balles.get(i);
ball.rebond();
ball.show();
}
}
1