I'm want to create an ArrayList that contains an Array and call the function of the objects inside that array.
I'm trying to call the function display() inside of the Array but I'm getting a NPE even though the array contains an object.
this is my code:
class Ball
{
int x;
int y;
int size;
color c;
Ball()
{
x = int (random(width));
y = int (random(height));
size = int (random(100));
c = color(random(255));
}
void display()
{
fill(c);
ellipse(x,y,size,size);
}
}
ArrayList<Ball[]> balls;
void setup()
{
size(500,500);
balls = new ArrayList<Ball[]>();
for( int i = 0; i < 1; i++)
{
balls.add(new Ball[2]);
println(balls);
}
}
void draw()
{
background(255);
for( int i = 0; i < 1; i++)
{
Ball[] b = balls.get(i);
b[i].display();
}
}
does anybody know how to do this?
balls.get(0)[0].display()would work