How can I solve an "Error: Cannot convert from Void to PImage"?

Hello!

I'm new to Processing and I'm writing some code. I must've done something wrong because "Error: Cannot convert from Void to PImage" appears. I've been trying to find an answer on the Internet, but nothing comes up.

Does anyone know how to solve it? Or where the error could come from?

Thanks

Answers

  • You likely have a method somewhere that returns void (nothing) and are trying to assign it to a PImage variable.

    void draw()
    {
        PImage image;
        image = someMethod();   //error!
        image = someOtherMethod(); //no error
    }
    
    void someMethod()
    {
        //does something
    }
    
    PImage someOtherMethod()
    { 
        PImage im = createGraphics(200,200);
        return im;
    }
    
  • In these cases it is convenient to post a minimum runnable example reproducing your problem.

    Kf

  • @marialopezsubi -- You are reading the error from the "Console" tab on the bottom of your editor window. Instead:

    1. Click on the "Errors" tab.
    2. Click on "Type mismatch, 'void' does not match...."

    You will see the line number listed on the right of the error message. The sketch window will scroll to the error line (or just above / below that line) and highlight it.

  • Thank you very much to all of you for your help. I'll try to solve the problem.

    What a great community this is.

Sign In or Register to comment.