[SOLVED] Setting PGraphics background in setup() causes NullPointerException?

I’m using the Java version for Processing and I’ve been following a tutorial on PGraphics which uses p5.js. At one point, they initialize the background for the PGraphics layer in setup. However, when I try it, it produces a null pointer error. I also tried using the P2D renderer, but it doesn’t solve the problem. Here’s a simplified example showing the problem:

PGraphics pg;

void setup() {
  size(600, 400);
  pg = createGraphics(600, 400);
  pg.background(0);
}

This doesn’t make any sense to me, since I’m pretty sure I’ve copied the code exactly, even though the example was in p5.js. Did I miss something obvious? Thanks for the help.

Ooops, 5 minutes after I submitted this, I realized that the js version doesn’t seem to need to use beginDraw() and endDraw(). Works fine now :grimacing:,

2 Likes