简体   繁体   English

将处理库导入 eclipse 时无法编译

[英]Cannot compile when importing Processing library into eclipse

I am trying to build a program using the Processing library in eclipse.我正在尝试使用 eclipse 中的 Processing 库构建一个程序。 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.我曾多次尝试导入处理库并在 Eclipse 和 IntelliJ 上编写简单程序,但都没有成功。

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.我已经卸载了 java JDK 并重新安装了它,但它没有任何区别。 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.升级到 JDK 9 后,我遇到了完全相同的问题。我在此处将其报告为问题( https://github.com/processing/processing/issues/5371 ),并收到确认处理 3 与 v9 不兼容。 For now, the only workaround is to downgrade to v8.目前,唯一的解决方法是降级到 v8。

I had the exact same problem on my Mac with eclipse projects.我在 Mac 上使用 eclipse 项目遇到了完全相同的问题。 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!所以我查找了处理应用程序内容并找到了它使用的 jdk(位于 Processing/Contents/Plugins/ )所以我将它用作我的项目的 jdk 并且它起作用了!

(I also installed the required libs (opengl ones) specified in core.jar contents (opened with Keka)) (我还安装了 core.jar 内容中指定的所需库(opengl 的)(用 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.无论如何,就像提到的 chrylis ,这是因为您的类路径不正确。 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.如何解决此问题取决于您使用的是哪个 IDE,但在 eclipse 中,您将右键单击您的项目,然后单击属性,然后转到左侧的Java Build Path部分。 Then go to the Libraries tab and add the Processing jars.然后转到Libraries选项卡并添加处理罐。

My guess is that you've added core.jar , which is all you need to compile your code.我的猜测是您已经添加了core.jar ,这是编译代码所需的全部内容。 But since you're running on a Mac, you need the Mac-specific jars as well.但由于您在 Mac 上运行,因此您还需要 Mac 特定的 jar。 You'll have to look in your Processing installation directory.您必须查看 Processing 安装目录。 Sorry I can't be more specific, but I don't have a Mac.对不起,我不能更具体,但我没有 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.意味着处理不能再使用内部 MacOS API,所以我在处理论坛上找到,为我解决了问题。

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.在挖掘之后,我发现 Processing 被滥用来添加适当的退出处理程序和设置停靠栏图标的内部 Mac API 现在已被删除并由官方 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. Processing 中有一个名为 ThinkDifferent 的类,当检测到 Mac 并且这个类正在调用现已删除的 API 时,它会通过反射加载。 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.为了解决这个问题,我使用新的官方 API 重新实现了这个类,并在我的项目中添加了一个新的 processing.core.ThinkDifferent 类来解决这个问题。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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