nullpointer execption ?
in
Programming Questions
•
2 years ago
I get this error at the end of the code :
- //DECLARE
- Ball [] ballCollection = new Ball[120];
- void setup (){
- size ( 600,600);
- smooth ();
- // Initialize the class
- for ( int i=0 ; i < 20; i++){
- ballCollection [i] = new Ball (random (0,width),random (0,200));
- }
- }
- void draw (){
- background (#FF0066);
- // CALL FUNCTIONALITY
- for ( int i =0 ; i< ballCollection.length ; i++){
- ballCollection[i].run();
- }
- }
- class Ball {
- //global vars
- float x = 0 ;
- float y = 0 ;
- float speedX = 8;
- float speedY = 6;
- // constructor*
- Ball (float _x, float _y) {
- x = _x ;
- y = _y ;
- }
- // functions
- void run(){
- display();
- move1 ();
- bounce();
- grav ();
- }
- void move1 (){
- x += speedX;
- y += speedY;
- }
- void bounce (){
- if ( x>width ){
- speedX = speedX*-1;
- }
- if ( x<0 ){
- speedX = speedX*-1;
- }
- if ( y>height ){
- speedY = speedY*-1;
- }
- if ( y<0 ){
- speedY = speedY*-1;
- }
- }
- void display (){
- noStroke ();
- ellipse ( x,y,20,20);
- }
- void grav (){
- speedY += 0.2;
- }
- }
Noise is king
1