Error: "Hello Processing" / JDK 10 / OSX High Sierra / com/apple/eawt/QuitHandler not supported

Hi,

I am trying to run a “Hello Processing” Java application (using Eclipse photon),
with OSX High Sierra (10.13.x), having Java jdk 10.
Is it supported?

This is the code:

import processing.core.PApplet;
public class UsingProcessing extends PApplet{
	public static void main(String[] args) {
		PApplet.main("UsingProcessing");
	}
}

This is the error I get:

java.lang.NoClassDefFoundError: com/apple/eawt/QuitHandler
	at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
	at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3119)
	at java.base/java.lang.Class.getMethodsRecursive(Class.java:3260)
	at java.base/java.lang.Class.getMethod0(Class.java:3246)
	at java.base/java.lang.Class.getMethod(Class.java:2065)
	at processing.core.PApplet.runSketch(PApplet.java:10707)
	at processing.core.PApplet.main(PApplet.java:10504)
	at processing.core.PApplet.main(PApplet.java:10486)
	at UsingProcessing.main(UsingProcessing.java:7)
Caused by: java.lang.ClassNotFoundException: com.apple.eawt.QuitHandler
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
	... 9 more

In a word no. You need to stick to jdk8, use of proprietary code in java has been warned about for years, finally they really mean it. Processing uses proprietary code com.apple.eawt.* in a number of areas to deal with MacOS specific foibles. See https://github.com/processing/processing/wiki/Supported-Platforms for when processing.org might do something about it. It might be worth trying to put this jar https://github.com/processing/processing/blob/master/core/apple.jar on your path.

2 Likes

I’m very late to the party, but I found this post because I had the exact same issue in April 2021, running Java 11 on Mac with the latest 3.3.7 Processing core.jar. After digging around I found that the internal Mac APIs that Processing has been misusing to add a proper quithandler and set a dock icon has now been removed and replaced by official AWT APIS. There is a class inside Processing called ThinkDifferent that is loaded by reflection when Mac is detected and this class was calling the now removed APIs. To solve this I reimplemented this class using the new official APIs and just added a new processing.core.ThinkDifferent class to my project that solved the issue.

package processing.core;

import java.awt.Desktop;
import java.awt.Image;
import java.awt.Taskbar;
import java.awt.desktop.QuitEvent;
import java.awt.desktop.QuitHandler;
import java.awt.desktop.QuitResponse;

public class ThinkDifferent {

  // True if user has tried to quit once. Prevents us from cancelling the quit
  // call if the sketch is held up for some reason, like an exception that's
  // managed to put the sketch in a bad state.
  static boolean attemptedQuit;

  public static void init(final PApplet sketch) {
    Desktop desktop = Desktop.getDesktop();
    desktop.setQuitHandler(
        new QuitHandler() {
          @Override
          public void handleQuitRequestWith(QuitEvent e, QuitResponse response) {
            sketch.exit();
            if (PApplet.uncaughtThrowable == null && !attemptedQuit) {
              response.cancelQuit();
              attemptedQuit = true;
            } else {
              response.performQuit();
            }
          }
        });
  }

  public static void cleanup() {
    Desktop.getDesktop().setQuitHandler(null);
  }

  // Called via reflection from PSurfaceAWT and others
  public static void setIconImage(Image image) {
    Taskbar.getTaskbar().setIconImage(image);
  }
}
2 Likes

thank you Paul, this allowed me to use Processing in Visual Studio Code with JDK 11 on Mac OS 12.3.

@paulrene Thanks for that code

I’m trying to run processing in Maven, but I can’t edit the .ThinkDifferent.class file in the Maven dependency.
Any idea on how I can still get it to work with your code?