Cannot compile when importing Processing library i

2020-04-20 12:33发布

问题:

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.

回答1:

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.



回答2:

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



回答3:

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.