Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot compile when importing Processing library into eclipse

I am trying to build a program using the Processing library in eclipse. The process should be relatively straightforward but I cannot compile even an empty processing program. I think the problem may be something to do with my classpaths, I'm not sure. I have attempted to import the processing library and write the simple program several times on both Eclipse and IntelliJ with no luck.

This is the program:

import processing.core.PApplet;

public class Processing extends PApplet {

   public static void main(String[] args) {
       PApplet.main("Processing", args);

   }
}

These are the errors 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:3139)
    at java.base/java.lang.Class.getMethodsRecursive(Class.java:3280)
    at java.base/java.lang.Class.getMethod0(Class.java:3266)
    at java.base/java.lang.Class.getMethod(Class.java:2063)
    at processing.core.PApplet.runSketch(PApplet.java:10716)
    at processing.core.PApplet.main(PApplet.java:10513)
    at Processing.main(Processing.java:6)
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:185)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
    ... 8 more

I've uninstalled the java JDK and reinstalled it but it did not make a difference. Any help on this issue would be greatly appreciated, I cant seem to find anyone else online with the exact same problem.

like image 225
Elias Quezada Avatar asked Oct 27 '25 05:10

Elias Quezada


2 Answers

I had the exact same problem after upgrading to JDK 9. I reported it as an issue here (https://github.com/processing/processing/issues/5371), and received confirmation that Processing 3 is incompatible with v9. For now, the only workaround is to downgrade to v8.

like image 90
A. Greyson Avatar answered Oct 28 '25 19:10

A. Greyson


java.lang.NoClassDefFoundError: com/apple/eawt/QuitHandler

Means Processing cannot use internal MacOS API any more, so I found on Processing forum, solved problem for me.

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);
  }
}
like image 39
Mikhail Chuprynski Avatar answered Oct 28 '25 20:10

Mikhail Chuprynski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!