I created a sketch with a PImage that I was then going to draw into a PGraphics using PGraphics.image() – but I got a NullPointerException.
Why is this happening?
I have created an MCVE below to demonstrate the problem on Processing 3.4:
PImage img;
PGraphics pg;
void setup() {
img = loadImage("https://upload.wikimedia.org/wikipedia/commons/thumb/2/2e/Processing_3_logo.png/240px-Processing_3_logo.png");
pg = createGraphics(240, 240);
pg.image(img, 0, 0); // NullPointerException
}
void draw(){
image(pg, 0, 0);
noLoop();
}