null pointer exception when loading image in settings P3.1.1

PImage canvas;PImage paint;
void settings(){
selectInput("Please select canvas:", "selectImage");
canvas = loadImage(input);
size(canvas.width, canvas.height);

Posted this as a bug they are saying that I am doing it wrong.....but works fine in 3.1

If there a better way of doing this???image is loaded....github seems very fixing one thing often messes up other stuff.


  • edited May 2018 Answer ✓

    I don't have specifically P3.1, but P3.1.1 & P3.0.2.
    I've done a more complete example below.
    It works for P3.0.2, but fails for P3.1.1! ~X(

     * selectInput() for loadImage() in settings() (v1.1)
     * GoToLoop (2016-May-19)
     * null-pointer-exception-when-loading-image-in-settings-p3-1-1#Item_1
    static final String RENDERER = JAVA2D; // JAVA2D, FX2D, P2D, P3D, OPENGL
    PImage canvas;
    void settings() {
      selectInput("Please select canvas picture:", "selectImage");
      while (canvas == null)  delay(100);
      size(canvas.width, canvas.height, RENDERER);
    void draw() {
    void selectImage(final File f) {
      if (f == null || f.isDirectory()) {
        println("Window was closed or you've hit cancel.");
      final String canvasPath = f.getPath();
      if ((canvas = loadImage(canvasPath)) == null) {
        println("is invalid image file. Try again...\n");
        selectInput("Please select canvas picture:", "selectImage");
  • yes I remember that processing was changed so you could do this and then they changed it back....thanks for the info.

  • edited June 2016 Answer ✓
    • We couldn't load anything within settings() b/c private field sketchPath wasn't initialized yet.
    • Then in replying to some GitHub issue, they've yielded and initialized both sketchPath & args[] early, making them available within settings().
    • Well, that's still true, but somehow P3.1.1 made some changes which are triggering some "mysterious" Java's "security" issues.
    • Therefore, it's a regression which @benfry prefers to close and sweep under the rug. :-@

Sign In or Register to comment.