colorMode throws nullPointerException (java - eclipse)

Hello. I’m coding my project in Eclipse. I’m trying to change the colorMode to HSB:

import processing.core.PApplet;
public void settings(){
public class mySketch extends PApplet{

	public static void main(String[] args) {
		String[] processingArgs = {"MySketch"};
		MySketch mySketch = new MySketch();
		PApplet.runSketch(processingArgs, MySketch);
	}

	public void settings() {
  	g.colorMode(HSB);
	println(g.colorMode); 
	}
}

both lines result in a NullPointerException error:

java.lang.NullPointerException
	at mySketch.settings(mySketch.java:58)
	at processing.core.PApplet.handleSettings(PApplet.java:978)
	at processing.core.PApplet.runSketch(PApplet.java:10897)
	at mySketch.main(mySketch.java:26)

Help!
Thank you
L.

1 Like

What does the g stand for? Is it initialized properly?

It’s the reference to the PApplet’s default PGraphics if I understand the doc correctly

https://processing.github.io/processing-javadocs/core/index.html?processing/core/PApplet.html

Were you able to resolve this issue?

I believe that you need to manipulate g in setup() – not settings().

Here is the reference for settings():

Define size() in settings. Then g is initialized. Then you can configure it in setup().