# NullPointerException

**URL:** https://discourse.processing.org/t/nullpointerexception/5079
**Category:** Coding Questions
**Created:** [November 1, 2018, 2:38am UTC](https://discourse.processing.org/t/nullpointerexception/5079 "2018-11-01T02:38:18Z")
**Posts on this page:** 1
**Page:** 2

<div class="post-metadata">

### Author: ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)
#### Post date: [November 1, 2018, 9:05pm UTC](https://discourse.processing.org/t/nullpointerexception/5079/21 "2018-11-01T21:05:21Z")

</div>

Thats basically the Same like with adding one ball. Just for multiple times. Now there are 2 ways. Either just do this 10 times with a for (int i = 0 ; i \< howManyNewBalls; i++) around the whole thing. Or you change the code a bit for more efficiency.

```auto
void mousePressed() {
  if ( mouseButton == LEFT ) {
    if (!firstMousePress) {
      for (int i=0; i < bola.length; i++) {
        strokeWeight(2);
        warna = color(random(255), random(255), random(255));
        bola[i] = new Benda(mouseX, mouseY, random(30), warna);
      }
      firstMousePress = true;
    } else {
      Benda[] bolaTemp = new Benda[bola.length + 10];
      for (int i = 0; i < bola.length; i++) {
       bolaTemp[i] = bola[i]; 
      }
      for (int i = 0; i < 10; i++) {
        bolaTemp[bolaTemp.length-(i+1)] = new Benda(mouseX, mouseY, random(30), warna);
      }
      bola = bolaTemp;
    }
  }
}

```

[Previous page](https://discourse.processing.org/t/nullpointerexception/5079.md?page=1)
