title: java.lang.NullPointerException with a custom class in Processing
body: <p>Alright, I am a newbie at programming so I don't have the basics very clear (also my english is pretty bad). When I started this code, I wanted it to draw some points, keep them moving and if they were closer than X between them, then draw a line. But I wanted to make it a little bit more complicated and then add another class, which was intended to dont interact with the other class and draw a circle and some next to it, constrained within a rectangle (I tried to constrain them to a circle but... too much for my head for now). Well, the thing is that I think that the code is ""clear"", at least for the PC, and I don't know why am I getting this "java.lang.NullPointerException" error, because it doesn't show me where the error is.</p>
  
  <p>Any help will be very appreciated.</p>
  
  <pre><code>//Test nº1. An array of spheres which are randomly moving, connected between them if the distance is less than 50p.
  //The spheres' starting position are determined by the red(x) and green(y) color space from colordata from images.
  
  
  int[] tots = {#2d2a33, #8e8397, #160e19, #8263a9, #0f1723, #737a86, #2d2a33, #8e8497, #15101c, #965555, #1a2940, #9b7873, #080b12, #272b41, #211f33, #8b6659,
              #070719, #4c5985, #423444, #9c8696, #1a2d13, #799078, #30160e, #da9c7b, #2c2e3a, #6d798e, #28474f, #b63f10, #040c1a, #cf6c24, #442036, #a87d99,
              #19191a, #756d6e, #1a2828, #94b1a2, #060c15, #6d98c1, #284062, #9ab9be, #121720, #abb7c5, #6e6b9b, #282033};
  
  //--Malla--
  
  float xo, yo;
  
  int numMalla = 200;
  
  Malla[] ma = new Malla [numMalla]; 
  
  float x;
  float y;
  float angle = 0.0; // Direction of motion  
  //float speed = random(0.2, 0.8); // Speed of motion
  
  float diameter = 0.0;
  
  //----
  
  //--Errant--
  
  int numPiEr = 10;
  int e;
  
  float xoEr = width/2;
  float yoEr = height/2;
  float xoPiEr = xoEr;
  float yoPiEr = yoEr;
  float cRotO = 0;
  
  Errant ccEr;
  //Errant clEr;
  Errant[] piEr = new Errant [numPiEr];
  //----
  
  void setup() {
  //--Malla--
  //coords mapping into the original position
  xo = map( (tots[int(random(0,tots.length))]&amp; 0xFF0000)&gt;&gt;16, 0, 255, 0, width);
  yo = map( (tots[int(random(0,tots.length))]&amp; 0x00FF00)&gt;&gt;8, 0, 255, 0, height);
  //----  
  
  size(1024, 768,P2D);
  background(0);
  smooth();
  frameRate(25);
  //float rad = random(5.0,150.0);
  
  //--Malla--
  for (int i = 0; i &lt; ma.length; i++) {
  ma[i] = new Malla(random(10,width-10),random(10,height-10),angle);
  
  }
  //----
  //--Errant--
  
  Errant ccEr = new Errant (xoEr, yoEr, cRotO);
  //Errant clEr = new Errant (xoEr, yoEr, cRotO);
  
  for (int e = 0; e &lt; piEr.length; e++) {
    piEr[e] = new Errant(xoPiEr, yoPiEr, cRotO);
  }
  
  //----
  
  }
  
  
  void draw() {
  
    background(0);
  
    for (int i = 0; i &lt; ma.length; i++) {
      ma[i].maMove();
      for (int j = i + 1; j &lt; ma.length; j++) {
        if (ma[i].nearAnotherMalla(ma[j])) {
          ma[i].highlight();
        }
      }
      ma[i].display();
    } 
  
    for (int e = 0; e &lt; piEr.length; e++) {
      piEr[e].piErMove();
      piEr[e].piErDisplay();
  
    }
    ccEr.erMove();
    ccEr.errDisplay();
  }
  
  
  
  class Malla {
  
  float x,y;
  float diameter;
  float speedX, speedY;
  float angle;
  //int temps;
  //color c = color(255);
  Malla[] nearMalla = new Malla[numMalla];
  
  //----
  
    Malla(float xpos, float ypos, float dir) {
  
    xo = x;
    yo = y;
  
    x = xpos;
    y = ypos;
    //speedX = random(-0.2, 0.2);
    //speedY = random(-0.2, 0.2);
    speedX = random(-2, 2);
    speedY = random(-2, 2);
    //temps=0;
    //diameter = random(5, 13);
    diameter = 2.5;
    angle = dir;
  
  }
  
  //----
  
  void maMove() {
  
   /*  if(temps==10){
    speedX = random(-2, 2);
    speedY = random(-2, 2);
    temps=0;
     }
     ++temps;*/
  
     if(x+diameter &gt;= width+20) {
        speedX = -speedX;
      }  
      else if(x+diameter &lt;= -20) {
        speedX = -speedX;
      }
  
      if(y+diameter &gt;= height+20) {
        speedY = -speedY;  
      }
      else if(y+diameter &lt;= -20) {
         speedY = -speedY;
      }
  
      // angle += random(-0.13, 0.13);
  /* x += speedX;
   y += speedY;*/
  
       angle += random(-0.13, 0.13);
  
      x += cos(angle) * speedX;
      y += sin(angle) * speedY; 
  }
  
  //----
  
  void highlight() {
    //c = color(255,100);
    stroke(255,1);
    for (int i = 0; i &lt; ma.length; i++) {
    if (nearMalla[i] != null) {
  
      line(x, y, nearMalla[i].x, nearMalla[i].y);
    }
  }
   }
  
  //----
  
  void display() {
    //stroke(c);
    noStroke();
    //noFill();
    fill(255);
    ellipse(x,y,diameter,diameter);
    //c = color(0);
  }
  
  //----
  
   boolean nearAnotherMalla(Malla b) {
     boolean near = dist(x,y,b.x,b.y) &lt;= 60;
      for (int i = 0; i &lt; ma.length; i++) {
     if (near) {
         nearMalla[i] = b;
     } 
     else {
       nearMalla[i] = null;
     }
     }
     return near;
  
   }
  }
  </code></pre>
  
  <p>This is what doesn't work, the single object</p>
  
  <pre><code>class Errant {
  
    float xEr, yEr, xPiEr, yPiEr, cRot, velEr, velErX, velErY, velPiEr,  velPiErX, velPiErY;
    int ccDiam, clDiamX, clDiamY, piErDiam;
  
  
    Errant[] nearPiEr = new Errant[numPiEr];
  
    //----
  
    Errant(float xEr, float yEr, float cRot) {
  
      ccDiam = 15;
      clDiamX = 80;
      clDiamY = 70;
  
      xEr = xoEr;
      yEr = yoEr;
  
      xPiEr = random((xEr-20),(xEr+20));
      yPiEr= random((yEr-20), (yEr+20));
  
      cRot = cRotO;
  
      velEr = random(-3,3);
      velEr = velErX = velErY;
      velPiEr = random(-1.5,1.5);
      velPiEr = velPiErX = velPiErY;
    }
  
  
    void erMove() {
  
      if(xEr+clDiamX &gt;= width+100) {
        velErX = -velErX;
      }  
      else if(xEr+clDiamX &lt;= -100) {
        velErX = -velErX;
      }
  
      if(yEr+clDiamX &gt;= height+100) {
        velErY = -velErY;  
      }
      else if(yEr+clDiamX &lt;= -100) {
         velErY = -velErY;
      }
  
      cRot += random(-0.2,0.2);
      xEr = cos(cRot)*velEr;
      yEr = sin(cRot)*velEr;
  
    }
  
    void piErMove() {
  
      if(xPiEr &gt;= xEr+clDiamX) {
        velErX = -velPiErX;
      }  
      else if(xPiEr &lt;= xEr-clDiamX) {
        velErX = -velPiErX;
      }
  
      if(yPiEr &gt;= yEr+clDiamY) {
        velErY = -velPiErY;  
      }
      else if(yPiEr &lt;= xEr-clDiamY) {
         velErY = -velPiErY;
      }
  
      xPiEr = cos(cRot)*velPiEr;
      yPiEr = sin(cRot)*velPiEr;
  
    }
  
    void errDisplay () {
      noStroke();
      fill(#EFE4B0, 70);
  
      ellipse(xEr, yEr, 10, 10);
    }
  
    void piErDisplay () {
      fill(#EFC6B0, 50);
  
      ellipse(xPiEr, yPiEr, 1, 1);
    }
  
  }
  </code></pre>
  
  <hr>
  
  <p>Thanks in advance, girald0.</p>
  
  <p>This is the error message that I get in the console:</p>
  
  <pre><code>java.lang.RuntimeException: java.lang.NullPointerException
      at com.jogamp.common.util.awt.AWTEDTExecutor.invoke(AWTEDTExecutor.java:58)
      at jogamp.opengl.awt.AWTThreadingPlugin.invokeOnOpenGLThread(AWTThreadingPlugin.java:103)
      at jogamp.opengl.ThreadingImpl.invokeOnOpenGLThread(ThreadingImpl.java:206)
      at javax.media.opengl.Threading.invokeOnOpenGLThread(Threading.java:172)
      at javax.media.opengl.Threading.invoke(Threading.java:191)
      at javax.media.opengl.awt.GLCanvas.display(GLCanvas.java:541)
      at processing.opengl.PJOGL.requestDraw(PJOGL.java:688)
      at processing.opengl.PGraphicsOpenGL.requestDraw(PGraphicsOpenGL.java:1651)
      at processing.core.PApplet.run(PApplet.java:2256)
      at java.lang.Thread.run(Unknown Source)
  Caused by: java.lang.NullPointerException
      at punts_moviment_mapejats2.draw(punts_moviment_mapejats2.java:111)
      at processing.core.PApplet.handleDraw(PApplet.java:2386)
      at processing.opengl.PJOGL$PGLListener.display(PJOGL.java:862)
      at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:665)
      at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:649)
      at javax.media.opengl.awt.GLCanvas$10.run(GLCanvas.java:1289)
      at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1119)
      at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:994)
      at javax.media.opengl.awt.GLCanvas$11.run(GLCanvas.java:1300)
      at java.awt.event.InvocationEvent.dispatch(Unknown Source)
      at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
      at java.awt.EventQueue.access$200(Unknown Source)
      at java.awt.EventQueue$3.run(Unknown Source)
      at java.awt.EventQueue$3.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
      at java.awt.EventQueue.dispatchEvent(Unknown Source)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.run(Unknown Source)
  </code></pre>