nullpointerexception – One day all of my programs on processing written in java stoped working. How to solve these errors?

I am trying to run programs on processing I coded. They used to work fine, but one day they all stopped working and started showing the same error messages. the code below is one example.

int cellSize = 10;

float p0 = 50;
float p1 = 25;
float p2 = 0;
float p3 = 0;
float p4 = 0;
float p5 = 0;
float p6 = 0;
float p7 = 0;
float p8 = 0;
float pn1 = 25;
float pn2 = 0;
float pn3 = 0;
float pn4 = 0;
float pn5 = 0;
float pn6 = 0;
float pn7 = 0;
float pn8 = 0;


color zero = color(0,0,0);
color red = color(255, 0, 0);
color orange = color(255, 162, 0);
color yellow = color(255, 221, 0);
color yellowgreen = color(89, 255, 0);
color greenblue = color(0, 255, 213);
color blue = color(0, 140, 255);
color purple = color(0, 26, 255);
color pink = color(255, 0, 204);
color error = color(200,200,200);

int interval = 100;
int lastRecordedTime = 0;

boolean pause = false;

int[][] cells;
int[][] cellsrecord;

void setup() {
  size (1000, 500);
  cells = new int[width/cellSize][height/cellSize];
  cellsrecord = new int[width/cellSize][height/cellSize];
  
  basic();
  
  background(0);
}

void draw() {
  for (int x=0; x<width/cellSize; x++) {
    for (int y=0; y<height/cellSize; y++) {
      if (cells[x][y]==0) {
        fill(zero);
      }
      else if (cells[x][y]%8==1||cells[x][y]%8==-7) {
        fill(red);
      }
      else if (cells[x][y]%8==2||cells[x][y]%8==-6) {
        fill(orange);
      }
      else if (cells[x][y]%8==3||cells[x][y]%8==-5) {
        fill(yellow);
      }
      else if (cells[x][y]%8==4||cells[x][y]%8==-4) {
        fill(yellowgreen);
      }
      else if (cells[x][y]%8==5||cells[x][y]%8==-3) {
        fill(greenblue);
      }
      else if (cells[x][y]%8==6||cells[x][y]%8==-2) {
        fill(blue);
      }
      else if (cells[x][y]%8==7||cells[x][y]%8==-1) {
        fill(purple);
      }
      else if (cells[x][y]!=0 && cells[x][y]%8==0) {
        fill(pink);
      }
      else {
        fill(error);
      }
      rect (x*cellSize, y*cellSize, cellSize, cellSize);
    }
  }
  if (millis()-lastRecordedTime>interval) {
    if (!pause) { 
      iteration();
      lastRecordedTime = millis();
    }
  }
}

void iteration() {
  for (int x=0; x<width/cellSize; x++) {
    for (int y=0; y<height/cellSize; y++) {
      cellsrecord[x][y] = 0;
    }
  }
  int count=0;
  for (int x=0; x<width/cellSize; x++) {
    for (int y=0; y<height/cellSize; y++) {
      if (cells[x][y]!=0) {
        int E=0;
        int N=0;
        int W=0;
        int S=0;
        for (int xx=x-1; xx<=x+1; xx++) {
          for (int yy=y-1; yy<=y+1; yy++) {
            if (((xx>=0)&&(xx<width/cellSize))&&((yy>=0)&&(yy<height/cellSize))) {
              if (!((xx==x)&&(yy==y))) {
                if ((cells[xx][yy]%8==1)||(cells[xx][yy]%8==-7)) {
                  if ((xx==x-1)&&(yy==y-1)) {
                    N=N+1;
                  }
                  else if ((xx==x-1)&&(yy==y)) {
                    N=N+1;
                  }
                  else if ((xx==x-1)&&(yy==y+1)) {
                    W=W+1;
                  }
                  else if ((xx==x)&&(yy==y+1)) {
                    W=W+1;
                  }
                  else if ((xx==x+1)&&(yy==y+1)) {
                    S=S+1;
                  }
                  else if ((xx==x+1)&&(yy==y)) {
                    S=S+1;
                  }
                  else if ((xx==x+1)&&(yy==y-1)) {
                    E=E+1;
                  }
                  else if ((xx==x)&&(yy==y-1)) {
                    E=E+1;
                  }
                  //println(E,N,W,S,count);
                }
                else if ((cells[xx][yy]%8==2)||(cells[xx][yy]%8==-6)) {
                  if ((xx==x-1)&&(yy==y-1)) {
                    N=N+2;
                  }
                  else if ((xx==x-1)&&(yy==y)) {
                    N=N+1;
                    W=W+1;
                  }
                  else if ((xx==x-1)&&(yy==y+1)) {
                    W=W+2;
                  }
                  else if ((xx==x)&&(yy==y+1)) {
                    W=W+1;
                    S=S+1;
                  }
                  else if ((xx==x+1)&&(yy==y+1)) {
                    S=S+2;
                  }
                  else if ((xx==x+1)&&(yy==y)) {
                    S=S+1;
                    E=E+1;
                  }
                  else if ((xx==x+1)&&(yy==y-1)) {
                    E=E+2;
                  }
                  else if ((xx==x)&&(yy==y-1)) {
                    N=N+1;
                    E=E+1;
                  }
                  //println(E,N,W,S,count);
                }
                else if ((cells[xx][yy]%8==3)||(cells[xx][yy]%8==-5)) {
                  if ((xx==x-1)&&(yy==y-1)) {
                    N=N+2;
                    W=W+1;
                  }
                  else if ((xx==x-1)&&(yy==y)) {
                    N=N+1;
                    W=W+2;
                  }
                  else if ((xx==x-1)&&(yy==y+1)) {
                    W=W+2;
                    S=S+1;
                  }
                  else if ((xx==x)&&(yy==y+1)) {
                    W=W+1;
                    S=S+2;
                  }
                  else if ((xx==x+1)&&(yy==y+1)) {
                    S=S+2;
                    E=E+1;
                  }
                  else if ((xx==x+1)&&(yy==y)) {
                    S=S+1;
                    E=E+2;
                  }
                  else if ((xx==x+1)&&(yy==y-1)) {
                    E=E+2;
                    N=N+1;
                  }
                  else if ((xx==x)&&(yy==y-1)) {
                    E=E+1;
                    N=N+2;
                  }
                }
                else if ((cells[xx][yy]%8==4)||(cells[xx][yy]%8==-4)) {
                  if ((xx==x-1)&&(yy==y-1)) {
                    N=N+2;
                    W=W+2;
                  }
                  else if ((xx==x-1)&&(yy==y)) {
                    W=W+2;
                  }
                  else if ((xx==x-1)&&(yy==y+1)) {
                    W=W+2;
                    S=S+2;
                  }
                  else if ((xx==x)&&(yy==y+1)) {
                    S=S+2;
                  }
                  else if ((xx==x+1)&&(yy==y+1)) {
                    S=S+2;
                    E=E+2;
                  }
                  else if ((xx==x+1)&&(yy==y)) {
                    E=E+2;
                  }
                  else if ((xx==x+1)&&(yy==y-1)) {
                    E=E+2;
                    N=N+2;
                  }
                  else if ((xx==x)&&(yy==y-1)) {
                    N=N+2;
                  }
                  //println(E,N,W,S,count);
                }
                else if ((cells[xx][yy]%8==5)||(cells[xx][yy]%8==-3)) {
                  if ((xx==x-1)&&(yy==y-1)) {
                    W=W+2;
                    N=N+1;
                  }
                  else if ((xx==x-1)&&(yy==y)) {
                    W=W+2;
                    S=S+1;
                  }
                  else if ((xx==x-1)&&(yy==y+1)) {
                    S=S+2;
                    W=W+1;
                  }
                  else if ((xx==x)&&(yy==y+1)) {
                    E=E+1;
                    S=S+2;
                  }
                  else if ((xx==x+1)&&(yy==y+1)) {
                    E=E+2;
                    S=S+1;
                  }
                  else if ((xx==x+1)&&(yy==y)) {
                    E=E+2;
                    N=N+1;
                  }
                  else if ((xx==x+1)&&(yy==y-1)) {
                    N=N+2;
                    E=E+1;
                  }
                  else if ((xx==x)&&(yy==y-1)) {
                    N=N+2;
                    W=W+1;
                  }
                }
                else if ((cells[xx][yy]%8==6)||(cells[xx][yy]%8==-2)) {
                  if ((xx==x-1)&&(yy==y-1)) {
                    W=W+2;
                  }
                  else if ((xx==x-1)&&(yy==y)) {
                    S=S+1;
                    W=W+1;
                  }
                  else if ((xx==x-1)&&(yy==y+1)) {
                    S=S+2;
                  }
                  else if ((xx==x)&&(yy==y+1)) {
                    E=E+1;
                    S=S+1;
                  }
                  else if ((xx==x+1)&&(yy==y+1)) {
                    E=E+2;
                  }
                  else if ((xx==x+1)&&(yy==y)) {
                    N=N+1;
                    E=E+1;
                  }
                  else if ((xx==x+1)&&(yy==y-1)) {
                    N=N+2;
                  }
                  else if ((xx==x)&&(yy==y-1)) {
                    W=W+1;
                    N=N+1;
                  }
                  //println(E,N,W,S,count);
                }
                else if ((cells[xx][yy]%8==7)||(cells[xx][yy]%8==-1)) {
                  if ((xx==x-1)&&(yy==y-1)) {
                    W=W+1;
                  }
                  else if ((xx==x-1)&&(yy==y)) {
                    S=S+1;
                  }
                  else if ((xx==x-1)&&(yy==y+1)) {
                    S=S+1;
                  }
                  else if ((xx==x)&&(yy==y+1)) {
                    E=E+1;
                  }
                  else if ((xx==x+1)&&(yy==y+1)) {
                    E=E+1;
                  }
                  else if ((xx==x+1)&&(yy==y)) {
                    N=N+1;
                  }
                  else if ((xx==x+1)&&(yy==y-1)) {
                    N=N+1;
                  }
                  else if ((xx==x)&&(yy==y-1)) {
                    W=W+1;
                  }
                  //println(E,N,W,S,count);
                }
                else if (cells[xx][yy]%8==0) {
                  if ((xx==x-1)&&(yy==y-1)) {
                    N=N+0;
                  }
                  else if ((xx==x-1)&&(yy==y)) {
                    N=N+0;
                  }
                  else if ((xx==x-1)&&(yy==y+1)) {
                    N=N+0;
                  }
                  else if ((xx==x)&&(yy==y+1)) {
                    N=N+0;
                  }
                  else if ((xx==x+1)&&(yy==y+1)) {
                    N=N+0;
                  }
                  else if ((xx==x+1)&&(yy==y)) {
                    N=N+0;
                  }
                  else if ((xx==x+1)&&(yy==y-1)) {
                    N=N+0;
                  }
                  else if ((xx==x)&&(yy==y-1)) {
                    N=N+0;
                  }
                  //println(E,N,W,S,count);
                }
                //println(xx,yy);
              }
            }
          }
        }
        if (((x+E-W<width/cellSize)&&(x+E-W>=0))&&((y+S-N<height/cellSize)&&(y+S- 
           N>=0))) {
          cellsrecord[x+E-W][y+S-N] = cellsrecord[x+E-W][y+S-N] + cells[x][y];
        }
        count++;
        println(E,N,W,S,count);
      }
      else {
        continue;
      }
    }
  }
  for (int x=0; x<width/cellSize; x++) {
    for (int y=0; y<height/cellSize; y++) {
      cells[x][y] = cellsrecord[x][y];
    }
  }
}
void basic() {
  for (int x=0; x<width/cellSize; x++) {
    for (int y=0; y<height/cellSize; y++) {
      
      float state = random (100);
      if (p0+p1+p2+p3+p4+p5+p6+p7+p8+pn1+pn2+pn3+pn4+pn5+pn6+pn7+pn8 == 100) {
        if ( state <= p0 ) {
          state = 0;
        }
        else if ( p0 < state && state <= p0+p1 ) {
          state = 1;
        }
        else if ( p0+p1<state && state<=p0+p1+p2) {
          state = 2;
        }
        else if ( p0+p1+p2<state && state<=p0+p1+p2+p3 ) {
          state = 3;
        }
        else if ( p0+p1+p2+p3 < state && state<=p0+p1+p2+p4) {
          state = 4;
        }
        else if ( p0+p1+p2+p3+p4 < state && state<=p0+p1+p2+p4+p5) {
          state = 5;
        }
        else if ( p0+p1+p2+p3+p4+p5 < state && state<=p0+p1+p2+p4+p5+p6) {
          state = 6;
        }
        else if ( p0+p1+p2+p3+p4+p5+p6 < state && state<=p0+p1+p2+p4+p5+p6+p7) {
          state = 7;
        }
        else if ( p0+p1+p2+p3+p4+p5+p6+p7< state && state<=p0+p1+p2+p4+p5+p6+p7+p8) {
          state = 8;
        }
        else if ( p0+p1+p2+p3+p4+p5+p6+p7+p8< state && 
                state<=p0+p1+p2+p4+p5+p6+p7+p8+pn1) {
          state = -1;
        }
        else if ( p0+p1+p2+p3+p4+p5+p6+p7+p8+pn1< state && 
                state<=p0+p1+p2+p4+p5+p6+p7+p8+pn1+pn2) {
          state = -2;
        }
        else if ( p0+p1+p2+p3+p4+p5+p6+p7+p8+pn1+pn2< state && 
                state<=p0+p1+p2+p4+p5+p6+p7+p8+pn1+pn2+pn3) {
          state = -3;
        }
        else if ( p0+p1+p2+p3+p4+p5+p6+p7+p8+pn1+pn2+pn3< state && 
                state<=p0+p1+p2+p4+p5+p6+p7+p8+pn1+pn2+pn3+pn4) {
          state = -4;
        }
        else if ( p0+p1+p2+p3+p4+p5+p6+p7+p8+pn1+pn2+pn3+pn4< state && 
                state<=p0+p1+p2+p4+p5+p6+p7+p8+pn1+pn2+pn3+pn4+pn5) {
          state = -5;
        }
        else if ( p0+p1+p2+p3+p4+p5+p6+p7+p8+pn1+pn2+pn3+pn4+pn5< state && 
                state<=p0+p1+p2+p4+p5+p6+p7+p8+pn1+pn2+pn3+pn4+pn5+pn6) {
          state = -6;
        }
        else if ( p0+p1+p2+p3+p4+p5+p6+p7+p8+pn1+pn2+pn3+pn4+pn5+pn6< state && 
                state<=p0+p1+p2+p4+p5+p6+p7+p8+pn1+pn2+pn3+pn4+pn5+pn6+pn7) {
          state = -7;
        }
        else if ( p0+p1+p2+p3+p4+p5+p6+p7+p8+pn1+pn2+pn3+pn4+pn5+pn6+pn7< state && 
                state<=p0+p1+p2+p4+p5+p6+p7+p8+pn1+pn2+pn3+pn4+pn5+pn6+pn7+pn8) {
          state = -8;
        }
        cells[x][y] = int(state);
      }
      else {
        textSize(128);
        fill(200,200,200);
        text("Hey man yolo! sum of probability has to be 100", 40,40);
      }
    }
  }
}

void keyPressed() {
  if (key=='r' || key=='R') {
    basic();
  }
  if (key==' ') {
    pause = !pause;
  }
  if (key=='c'||key=='C') {
   for (int x=0; x<width/cellSize; x++) {
    for (int y=0; y<height/cellSize; y++) {
      cells[x][y] = 0;
    }
   }
  }
  if (pause && ((key=='p'||key=='P')||(key=='o'||key=='O'))) {
    if (key=='p'||key=='P') {
      iteration();
    }
  }
  if (pause && mousePressed) {
    int xCellOver = int(map(mouseX, 0, width, 0 , width/cellSize));
    xCellOver = constrain(xCellOver, 0, width/cellSize-1);
    int yCellOver = int(map(mouseY, 0, height, 0, height/cellSize));
    yCellOver = constrain(yCellOver, 0, height/cellSize-1);
    
    if (key=='0') {
      cells[xCellOver][yCellOver]=0;
    }
    else if (key=='1') {
      cells[xCellOver][yCellOver]=1;
    }
    else if (key=='2') {
      cells[xCellOver][yCellOver]=2;
    }
    else if (key=='3') {
      cells[xCellOver][yCellOver]=3;
    }
    else if (key=='4') {
      cells[xCellOver][yCellOver]=4;
    }
    else if (key=='5') {
      cells[xCellOver][yCellOver]=5;
    }
    else if (key=='6') {
      cells[xCellOver][yCellOver]=6;
    }
    else if (key=='7') {
      cells[xCellOver][yCellOver]=7;
    }
    else if (key=='8') {
      cells[xCellOver][yCellOver]=8;
    }
    else if (key=='a') {
      cells[xCellOver][yCellOver]=-1;
    }
    else if (key=='s') {
      cells[xCellOver][yCellOver]=-2;
    }
    else if (key=='d') {
      cells[xCellOver][yCellOver]=-3;
    }
    else if (key=='f') {
      cells[xCellOver][yCellOver]=-4;
    }
    else if (key=='g') {
      cells[xCellOver][yCellOver]=-5;
    }
    else if (key=='h') {
      cells[xCellOver][yCellOver]=-6;
    }
    else if (key=='j') {
      cells[xCellOver][yCellOver]=-7;
    }
    else if (key=='k') {
      cells[xCellOver][yCellOver]=-8;
    }
    
  }
  //else if (pause && !mousePressed) {
  //  for (int x=0; x<width/cellSize; x++) {
  //    for (int y=0; y<height/cellSize; y++) {
  //      cellsBuffer[x][y] = cells[x][y];
  //    }
  //  }
  //}
}

and these error messages pop up. The same error messages pop up for other programs I coded as well.

java.lang.NullPointerException
    at processing.app.Library.getClassPath(Library.java:361)
    at processing.mode.java.JavaBuild.preprocess(JavaBuild.java:270)
    at processing.mode.java.JavaBuild.preprocess(JavaBuild.java:144)
    at processing.mode.java.JavaBuild.build(JavaBuild.java:110)
    at processing.mode.java.JavaBuild.build(JavaBuild.java:92)
    at processing.mode.java.JavaMode.handleLaunch(JavaMode.java:112)
    at processing.mode.java.JavaEditor.lambda$handleLaunch$27(JavaEditor.java:1019)
    at java.base/java.lang.Thread.run(Thread.java:829)

Does an update of processing or java cause this? I have no idea why, can anyone help?

Leave a Comment