title: How to call function of an Array in ArrayList? Java
body: <p>I'm want to create an ArrayList that contains an Array and call the function of the objects inside that array. </p>
  
  <p>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.</p>
  
  <p>this is my code:</p>
  
  <pre><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&lt;Ball[]&gt; balls;
  
  
  void setup()
  {
    size(500,500);
  
    balls = new ArrayList&lt;Ball[]&gt;();
  
    for( int i = 0; i &lt; 1; i++)
    {
      balls.add(new Ball[2]);
      println(balls);
    }
  }
  
  void draw()
  {
    background(255);
  
    for( int i = 0; i &lt; 1; i++)
    {
      Ball[] b = balls.get(i);
      b[i].display();
    }
  }
  </code></pre>
  
  <p>does anybody know how to do this?</p>