Running a Processing 4 PApplet in Eclipse IDE

I’ve been developing a library for Processing 4 in the Eclipse IDE, using the Processing Library Template. It would be handy to test a PApplet within the library, rather that running it in Processing. However, I can’t get my code to run, even this very basic example:

package net.paulhertz.pixelaudio;
import processing.core.PApplet;

public class TestPixelAudio extends PApplet {

	public void setup() {
		size(1024, 1024);
	}
	
	public void draw() {
		
	}

	public static void main(String args[]) {
		PApplet.main(new String[] { "--present", "TestPixelAudio" });
	}
}

My problem seems to be the following:

java.lang.UnsupportedClassVersionError: processing/core/PApplet has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 52.0

I am not running the Ant script to compile a library, just compiling with “Build All” in the Project menu, apparently with success. The library build works just fine.

I’ve compiled with JRE 17, but it would seem that I need a more recent version for the current version of Processing 4.0. What should that be?

I suppose that in the long run, I should try to use this template in IntelliJ IDEA https://github.com/processing/processing-library-template-gradle, but Eclipse has been my go-to IDE for a long time.

cheers,

Paul

Looks like its using actually Java 8 (class v52).
If your project is certainly using 17, then the problem might be the run config pointing to Java 8.

Example:

1 Like

Need to use settings in Eclipse

    public void settings() {
		size(1024, 1024);
	}

    public void setup() {
		// Normal stup code stuff
	}
2 Likes

I was configuring Eclipse and the build path to use Java 17. I must have missed something.

I think checking Java 1.8 compatibility, even though I was compiling with 17, may have caused problems. With that unchecked, I am not getting the same error – that’s a plus. However, now Eclipse lodges a java.lang.ClassNotFoundException. Odd, considering that I am looking at the .class file in the bin directory where it ought to be. But at least a step in the right direction, I think.

Added the settings() method, too.

thanks,

Paul

I still get a FileNotFoundException even with a fully qualified path:

java.lang.RuntimeException: java.lang.ClassNotFoundException: /Users/paulhz/Code/Workspace/PixelAudio/bin/net/paulhertz/pixelaudio/TestPixelAudio
at processing.core.PApplet.runSketch(PApplet.java:10074)
at processing.core.PApplet.main(PApplet.java:9845)
at net.paulhertz.pixelaudio.TestPixelAudio.main(TestPixelAudio.java:20)
Caused by: java.lang.ClassNotFoundException: /Users/paulhz/Code/Workspace/PixelAudio/bin/net/paulhertz/pixelaudio/TestPixelAudio
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
at processing.core.PApplet.runSketch(PApplet.java:10067)
… 2 more

I’m trying to run my code as a Java Application. I think that’s the only choice, since Applets are no longer supported.

You can see from the error message that TestPixelAudio.main is actually being called by PApplet. The Run Configuration points to net.paulhertz.pixelaudio.TestPixelAudio, which seems correct to me.

The repository is here: https://github.com/Ignotus-mago/PixelAudio.

// Paul

Solved. If the PApplet child is in a package, you need to include the package reference:

	public static void main(String args[]) {
		PApplet.main(new String[] { "net.paulhertz.pixelaudio.TestPixelAudio" });
	}

Thanks again @quark and @micycle, you comments were spot on:

– For Processing 4, make sure all relevant build path settings use Java 17
– Use the settings() method to set window width and height

Also check out @quark’s suggestion in post #9:

// Paul

I tend to use the .main() method signature that takes a .class object, rather than string name. It helps to avoid this kind of problem (and will continue to work if you rename the class).

3 Likes

My fav has always been PApplet.runSketch(), which accepts an array of strings w/ options such as " --sketch-path", and a PApplet instance as its 2nd argument:

https://Processing.GitHub.io/processing-javadocs/core/processing/core/PApplet.html#runSketch-java.lang.String:A-processing.core.PApplet-

3 Likes

I have used Eclipse (since 2009) for developing several Processing libraries and I have found the following strategy works for me.

A minimum of two Eclipse projects
Project 1
This contains the source code , resources, ant scripts etc. to build the library.

Project 2.
This project contains all the tests, experiments and demo sketches used while developing the library.

In both projects the library path will be linked to any necessary Processing jars .

In project 2 we don’t link to our library jar rather we link to the actual library project. This makes debug mode and stepping through code so much more useful as it just slips into the library code.

My favourite way of coding main is

public class TestPixelAudio extends PApplet {

	public static void main(String[] args) {
		PApplet.main(new String[]{TestPixelAudio.class.getName()});
	}

This has two benefits

  1. the package name is included in the class name when using getName()
  2. Changing the class name through refactoring will automatically update the main() method
3 Likes

Nice. I already had the stub of a separate project.
I added my library project to its classpath and now can use it from the test project.

An example of using runSketch() in the PDE in order to have a separate PGraphics on a separate thread:

We config ARGS_SKETCH_FOLDER " --sketch-path" to match PApplet’s main sketch, so save functions know the root folder where the sketch is run:

final String[] switches = { ARGS_SKETCH_FOLDER + sketchPath(), "" };
runSketch(switches, layer = new Layer());

Layer is the 2nd PApplet subclass:

public static class Layer extends PApplet {
  static final short INTERVAL = 1*1000, TXT_SIZE = 40;
  static final float BOLD = 2.5;
  static final color BORDER = 0, TXT_COLOR = -1;

  PGraphics pg;
  PImage img;

  void settings() {
    size(1, 1, P2D);
  }
2 Likes

You can easily convert Processing code to Java with the export project button.
(Cntl+Shift+E or command+shift+E)