Processing with Java Classes and "background"

Re: Processing in Java

I am working on the code in the book “The Nature of Code”. I have one of the first examples, the Random Walk, working. Except for ONE problem (so far). Instead of using “setup()” like one would do in the Processing IDE, I realize we have to use “settings()”.

When I write the following code using “background”

public void settings() {
    size(640, 360);
    background(255);
    w = new Walker(this);

}

I get a null Pointer exception on execution of the “background(255)” statement.
If I put it in a “public void mousePressed()” method, I do not get a null Pointer exception. Why is background not accepted in the settings() method, and how is one supposed to initialize background in “settings()” if you cannot?

Thanks

When I have a problem like this, I try to isolate it to a small example program. For example if you’re only asking about the background() function, then you probably don’t need anything related to your Walker class to help isolate the problem.

But note that you can have both a settings() function and a setup() function, and you can move your call to background(255) into setup() without moving the rest of your code.

I appreciate the prompt reply. It works having both a settings() and setup() and putting the background(255) in the setup. I guess I should dig into the code and figure out why the background() doesn’t work in settings(). I hate having arbitrary concepts and not knowing why. I learned Java (back in 1997) by digging into the source code of the SDK. It was an enlightening process.

Again thanks.

Stephen McConnell