2 threads Processing in Java IDE

In the course of rebuilding a big Processing project in a Java IDE (IntelliJ) on Windows 10 x64, Processing 3.5.4, I try to translate the old solution for running two Processing threads, one in 2D, one in 3D on different screens:
The processing code can be found here: 3D renderer not recognized in secondApplet - Processing 2.x and 3.x Forum (scroll down to the last code version)
But with my Java code I get error messages in the IntelliJ IDE (see below). I suppose the problem is related to the runSketch method. Could anybody suggest how to solve this?

My Java code:

import processing.core.PApplet;
import processing.core.PShape;

public class TwoThreads extends PApplet {   
   
    public static void main(String[] args)
    {
        PApplet.main("TwoThreads", args);
    }

    public void settings() {
        size(400, 300, JAVA2D);
        smooth(3);
        noLoop();

        String[] args = {"SecondApplet"};
        SecondApplet sa = new SecondApplet();
        PApplet.runSketch(args, sa);
    }
   
    public void draw()
    {
        line(5, 5, 50, 50);
    }


    public class SecondApplet extends PApplet {
        Tetra tetra;
        float theta;
        public void settings() {
            size(400, 300, P3D);
        }

        public void setup() {
            frameRate(30);
            //PVector myVec = new PVector(width>>1, height>>1, 0300);
            //circle = new MyCircle(this, myVec, #FFFF00);

            tetra = new Tetra(this, 10);
            theta = (float) 0.0;
        }

        public void draw() {

            background(255);
            theta += 0.01;
            translate(width/2, height/2, 0);
            rotateX(theta);
            rotateY(theta);

            // translate the scene again
            translate(100, 100, 20);

            background(0100);
            //translate(mouseX, mouseY, 20);
            //circle.display();
            //translate(mouseX, mouseY, 0);
            tetra.display();
            //box(100);
        }

    }

    public class Tetra {

        final PApplet p;

        // The PShape object
        final PShape gr;
        int t;
        float speed;

        Tetra(PApplet pa, int t_) {
            p = pa;

            t = t_;

            gr = p.createShape();

            gr.beginShape(TRIANGLES);
            gr.fill(150, 0, 0, 127);
            gr.vertex(-t, -t, -t);
            gr.vertex( t, -t, -t);
            gr.vertex( 0, 0, t);

            gr.fill(0, 150, 0, 127);
            gr.vertex( t, -t, -t);
            gr.vertex( t, t, -t);
            gr.vertex( 0, 0, t);

            gr.fill(0, 0, 150, 127);
            gr.vertex( t, t, -t);
            gr.vertex(-t, t, -t);
            gr.vertex( 0, 0, t);

            gr.fill(150, 0, 150, 127);
            gr.vertex(-t, t, -t);
            gr.vertex(-t, -t, -t);
            gr.vertex( 0, 0, t);

            gr.endShape();
        }

        Tetra display() {
            //p.box(100);
            p.shape(gr);
            return this;
        }
    }
}

Error messages from IntelliJ IDE:

java.lang.NoClassDefFoundError: com/jogamp/opengl/GLCapabilitiesImmutable
at processing.opengl.PGraphicsOpenGL.createPGL(PGraphicsOpenGL.java:712)
at processing.opengl.PGraphicsOpenGL.(PGraphicsOpenGL.java:569)
at processing.opengl.PGraphics3D.(PGraphics3D.java:35)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at processing.core.PApplet.makeGraphics(PApplet.java:2266)
at processing.core.PApplet.createPrimaryGraphics(PApplet.java:2345)
at processing.core.PApplet.initSurface(PApplet.java:10983)
at processing.core.PApplet.runSketch(PApplet.java:10922)
at TwoThreads.settings(TwoThreads.java:19)
at processing.core.PApplet.handleSettings(PApplet.java:978)
at processing.core.PApplet.runSketch(PApplet.java:10897)
at processing.core.PApplet.main(PApplet.java:10657)
at TwoThreads.main(TwoThreads.java:9)
Caused by: java.lang.ClassNotFoundException: com.jogamp.opengl.GLCapabilitiesImmutable
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
… 16 more
java.lang.RuntimeException: com/jogamp/opengl/GLCapabilitiesImmutable
at processing.core.PApplet.makeGraphics(PApplet.java:2299)
at processing.core.PApplet.createPrimaryGraphics(PApplet.java:2345)
at processing.core.PApplet.initSurface(PApplet.java:10983)
at processing.core.PApplet.runSketch(PApplet.java:10922)
at TwoThreads.settings(TwoThreads.java:19)
at processing.core.PApplet.handleSettings(PApplet.java:978)
at processing.core.PApplet.runSketch(PApplet.java:10897)
at processing.core.PApplet.main(PApplet.java:10657)
at TwoThreads.main(TwoThreads.java:9)

Process finished with exit code 1

1 Like

When working outside Processing’s own IDE (PDE) we’ve gotta make sure we’re using Java 8. :warning:

I can’t see what else might be wrong in your code though. :anguished:

I am using java 1.8.0_421 in the IDE. This I have considered. But thanks for your reply.

The error above states it couldn’t find the definition for GLCapabilitiesImmutable:
JogAmp.org/deployment/jogamp-next/javadoc/jogl/javadoc/com/jogamp/opengl/GLCapabilitiesImmutable.html

It means the OpenGL 3D library JogAmp isn’t in the compiler’s classpath (-cp) option: JogAmp.org

1 Like

Are you sure you’ve imported all dependencies?

Yes I forgot to add the jogl jar files in the project. I downloaded the JOGL files resp. jogamp-all-platforms.7z Following this install description for Win 64bit I need at least the following 4 files:

  • gluegen-rt.jar
  • jogl-all.jar
  • gluegen-rt-natives-windows-amd64.jar
  • jogl-all-natives-windows-amd64.jar

I put these files into a folder in my project folder and try to set the dependency to it following these [instructions for intelliJ] (Ecllipse, Netbeans are described there as well)(https://jogamp.org/wiki/index.php/Setting_up_a_JogAmp_project_in_your_favorite_IDE). But the jar files don´t show up under external libraries resp. seem to be not identified as valid classes. Hm…

1 Like

Processing is quite comfortable and I forgot the dependencies for running it in a Java IDE.

Now after choosing the JOGL jars in IntelliJ from the Processing (program files) folder the error message disappeared after running the code. But now there is another error:

java.lang.RuntimeException: java.lang.ClassNotFoundException: TwoThreads_2
at processing.core.PApplet.runSketch(PApplet.java:10852)
at processing.core.PApplet.main(PApplet.java:10657)
at org.processing.twoThreads_2.TwoThreads_2.main(TwoThreads_2.java:10)
Caused by: java.lang.ClassNotFoundException: TwoThreads_2
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at processing.core.PApplet.runSketch(PApplet.java:10845)
… 2 more

I found many posts about this problem concerning IntelliJ´s IDE specific reasons e.g. here

1 Like

ok now after building this anew it runs. The case was the dependency from the JOGL files all to find in the processing installation library folder together with the core.jar.

Thanks for the helpful feedback!

2 Likes

Only if you’re on macOS, and mostly workaround-able if you are.

I would copy the JOGL files from inside a Processing install or from processing/core/library at master · processing/processing · GitHub - some things might be patched, which may or may not be relevant.

2 Likes