title: Adding new object by pressing left mouse
body: <p>Got an array of <code>Object</code> instances (<code>Sprites</code>), got method to add a new object to array by pressing left mouse button:</p>
  <pre><code>private void addSprite() {
          addMouseListener(new MouseAdapter() {
              @Override
              public void mousePressed(MouseEvent e) {
                  int x = e.getX();
                  int y = e.getY();
                  Sprite sprite = new Ball(x, y);
                  if (sprites[sprites.length - 1] == null){
                      sprites[sprites.length - 1] = sprite;
                  }else if (sprites[sprites.length - 1] != null){
                      Sprite[] temp = new Sprite[sprites.length * 2];
                      System.arraycopy(sprites, 0, temp, 0, sprites.length);
                      sprites = temp;
                  }
  
              }
          });
      }
  </code></pre>
  <p>If <code>arr</code> is full I create new temporary array, size of <code>sprites.length * 2</code>, and copy all elements in a <code>temporary array</code>, and change link <code>sprites = temp</code>, and I've got <code>NullPointerException</code>. Task is adding new objects using only arrays, not <code>ArrayList</code>.</p>
  <p>What am I doing wrong?</p>