I'm trying to recreate tetris using processing for a school project.
But I keep getting nullPointerExceptions when trying to call the fill
function
this is the class:
package nl.HAN.game.eindOpdracht;
import processing.core.PApplet;
public class Block {
private PApplet app;
private int xPos;
private int yPos;
private int width;
private int height;
private boolean exploded;
public Block(PApplet app, int xPos, int yPos) {
//standaard
this.app = app;
this.xPos = xPos;
this.yPos = yPos;
this.width = (app.width / 3) / 10;
this.height = app.height / 20;
this.exploded = false;
}
public boolean isExploded() {
return exploded;
}
public void explode(){
this.exploded = true;
}
public void drop(){
this.yPos++;
}
public void move(int direction){
if(direction == 0){
this.xPos++;
} else {
this.xPos--;
}
}
public void draw(){
if(!exploded){
app.fill(200, 100, 100);
}
}
}
this is the main class:
public static void main(String[] args) {
PApplet app = new PApplet();
//app.print("test");
Block block = new Block(app, 1, 1);
//block.draw();
app.fill(255);
String[] processingArgs = {"nl.han.ica.oopd.waterworld.WaterWorld"};
Main mySketch = new Main();
//PApplet.runSketch(processingArgs, mySketch);
}
and this is the error:
Exception in thread "main" java.lang.NullPointerException
at processing.core.PApplet.fill(PApplet.java:14739)
at nl.HAN.game.eindOpdracht.Main.main(Main.java:18)