IntelliJ Idea 14.4.14 & Processing 3.0

edited August 2015 in Using Processing

Hy, i am a programmer in IntelliJ and just stumbled on processing by accident. I really like it. I would like to use it's functionality in IntelliJ where i do most of my work, but i have been struggling with it for the past day... So what do i do: First i make a new Java 1.8 SDK Project. Then i include core.jar into the project.

Then i make the main:

package com.company;
import processing.core.*;
public class Main {
    public static void main(String[] args) {
        System.out.println("Begin...");
        Processingex taat = new Processingex();
        taat.setup();
    }
}

and the processing "part":

package com.company;
import processing.core.PApplet;
public class Processingex extends PApplet{
    public void setup() {
        size(500, 500);
        background(0);
    }
}

The program does not work, and it outputs: When not using the PDE, size() can only be used inside settings(). Remove the size() method from setup(), and add the following:

public void settings() {
  size(500, 500);
}
Exception in thread "main" java.lang.IllegalStateException: size() cannot be used here, see https://processing.org/reference/size_.html
    at processing.core.PApplet.insideSettings(PApplet.java:936)
    at processing.core.PApplet.size(PApplet.java:1968)
    at com.company.Processingex.setup(Processingex.java:10)
    at com.company.Main.main(Main.java:14)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)

Process finished with exit code 1

I really do not know what the problem is, and have tried various things including:

  • copy paste a tutorial code (did not work)
  • reinstall IntelliJ (did not work)
  • reintalled Java (did not work)
  • tried different enviroments(NetBeans, Eclipse) (did not work)
  • Processing enviroment (worked)

Why does it not work in IntelliJ??? I shall go mental if i do not figure this one out :/

Answers

  • The solution is in the error: add a new method settings() and call size() from there.

    void settings()
    {
       size(500,500);
    }
    
    void setup()
    {
       //other setup code
    }
    

    This is something that changed recently so you'll have to modify a lot of existing sketches. What Processing does when it compiles from its own IDE is move the size call from setup to settings. This means you can no longer use variables inside setup. (Previously Processing would run setup until it encountered the size() method, which would cause an error as the Applet had already been initialized with default width and height, so Processing would create a new instance with the correct parameters. Or something.)

  • I don't know if it matters but it's more common to do it like this:

    package com.company; 
    import processing.core.*; 
    
    
    public class Main extends PApplet { 
    
      public static void main(String[] args) { 
        PApplet.main("com.company.Main", args);
      }  
    
    }
    

    The string should be the package name followed by the class name. If you get a ClassNotFoundException then you know you did it wrong :)

Sign In or Register to comment.