简体   繁体   中英

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.

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.

I had the exact same problem on my Mac with eclipse projects. But processing app was compiling fine by itself. So I looked up in processing app contents and found the jdk it uses (located in Processing/Contents/Plugins/ ) So I used it as my jdk with my project and it worked!

(I also installed the required libs (opengl ones) specified in core.jar contents (opened with Keka))

I cannot compile even an empty processing program.

This is not a compiler error. This is a runtime error.

Anyway, like chrylis mentioned , this is because your classpath is not correct. How you fix this depends on which IDE you're using, but in eclipse you would right-click your project, then click properties, then go to the Java Build Path section on the left. Then go to the Libraries tab and add the Processing jars.

My guess is that you've added core.jar , which is all you need to compile your code. But since you're running on a Mac, you need the Mac-specific jars as well. You'll have to look in your Processing installation directory. Sorry I can't be more specific, but I don't have a Mac.

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);
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM