Java ClassNotFoundException使用处理';带Arduino工具的s PApplet

Java ClassNotFoundException使用处理';带Arduino工具的s PApplet,java,eclipse,processing,classnotfoundexception,arduino-ide,Java,Eclipse,Processing,Classnotfoundexception,Arduino Ide,我开发了一个基本的PApplet,作为中的工具运行,在Arduino 1.5.8之前运行良好。我遇到的问题是,在Arduino 1.6.0中,一些代码被重构,这发生在Arduino端: “为了提供更好的命令行,对IDE进行了重构 进入应用程序和arduino核心,这是旧的核心,以避免 类之间的冲突,PApplet从 processing.core.PApplet到processing.app.legacy.PApplet” 这一解释来自ArduinoIDE开发人员之一。值得注意的是,proces

我开发了一个基本的PApplet,作为中的工具运行,在Arduino 1.5.8之前运行良好。我遇到的问题是,在Arduino 1.6.0中,一些代码被重构,这发生在Arduino端:

“为了提供更好的命令行,对IDE进行了重构 进入应用程序和arduino核心,这是旧的核心,以避免 类之间的冲突,PApplet从
processing.core.PApplet
processing.app.legacy.PApplet

这一解释来自ArduinoIDE开发人员之一。值得注意的是,processing.app.legacy.PApplet是一个(非常)精简版的PApplet,丢弃了我需要的所有图形功能

最初我遇到了这个错误:

Uncaught exception in main method: java.lang.NoClassDefFoundError: processing/core/PApplet
将Processing的core.jar与eclipse导出的工具jar放在同一位置修复了此问题,但让我们转到另一个位置:

Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: You need to use "Import Library" to add processing.core.PGraphicsJava2D to your sketch.
    at processing.core.PApplet.makeGraphics(Unknown Source)
    at processing.core.PApplet.init(Unknown Source)
令人困惑的是,我使用了Processing的库源java文件而不是core.jar编译库来避免这个问题,但它没有改变任何东西

我浏览了PApplet的源代码,发现graphics/renderer类在运行时被加载和实例化,如下所示:

我对java越来越熟悉,但我没有足够的经验来理解这一点。这看起来像是一个类路径问题,但我不确定为什么会发生这种情况,以及我应该如何告诉java在哪里找到它需要加载的类

下面是我使用的基于IDE附带的Arduino工具示例的代码测试。目前,我正在从eclipse导出jar文件(不可运行):

/*
  Part of the Processing project - http://processing.org

  Copyright (c) 2008 Ben Fry and Casey Reas

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software Foundation,
  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

package com.transformers.supermangletron;


import java.awt.Color;
import java.awt.Dimension;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import processing.core.PApplet;
import processing.app.Editor;
import processing.app.tools.Tool;
//import processing.app.legacy.PApplet;

/**
 * Example Tools menu entry.
 */
public class Mangler implements Tool {
  private Editor editor;

  public void init(Editor editor) {
    this.editor = editor;
  }

  private void setupSketch(){
    int w = 255;
    int h = 255;

//      PApplet ui = new PApplet();
    TestApp ui = new TestApp();

      JFrame window = new JFrame(getMenuTitle());
      window.setPreferredSize(new Dimension(w,h+20));

    window.add(ui);
      window.invalidate();
      window.pack();
      window.setVisible(true);
      window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      ui.init();

    System.out.println("setup complete");
  }

  public String getMenuTitle() {
    return "Mangle Selection";
  }


  public void run() {
      setupSketch();
  }

}
下面是我试图显示的基本测试小程序:

package com.transformers.supermangletron;

import processing.core.PApplet;

public class TestApp extends PApplet {
    public void setup(){
        size(100,100);
    }
    public void draw(){
        background((1.0f+sin(frameCount * .01f)) * 127);
    }
}
如何用我的设置修复ClassNotFoundException?
关于类路径我应该仔细检查哪些方面的提示?

如果从eclipse运行时出现此错误,则必须将库JAR添加到类路径中。您可以通过右键单击项目,转到属性,然后转到Java构建路径来实现这一点。确保库jar列在“库”选项卡下


如果在运行导出的jar时出现此错误,则需要执行以下两项操作之一:

或者确保导出一个可运行的jar,并将库jar嵌入到主jar中。在eclipse中,右键单击项目,转到Export,然后从列表中选择“runnable jar”来实现这一点


或者,确保将类路径设置为JVM参数。您可以使用命令行中的-cp选项来执行此操作。

嗨,Kevin,不幸的是,我的情况几乎没有限制。以前,当我使用Processing的core.jar时,我确实确保将库添加到构建路径(并在Libraries选项卡中列出)。现在,我在与我的两个测试类相同的源路径中使用库的源代码。我需要额外做什么吗?关于runnable jar,这不适用。我正在构建一个Arduino工具,它本质上是实现一个接口。这是由Arduino IDE调用的,因此在工具实现中没有main()/入口点……与上面类似,因为工具是由Arduino IDE实例化/创建的,所以我无法控制命令行参数(如-cp)。你能想出在运行时找不到这些类的其他原因吗?我不确定我是否理解-当你说你在使用库的源代码时,你是什么意思?您的问题的基本答案是,您需要在主jar中包含库jar,或者将它们设置为类路径作为参数。您选择哪一个以及如何选择完全取决于您的设置。通过使用库的源代码,我的意思是我复制到eclipse项目的src文件夹中。在仔细检查core.jar是否位于项目构建路径设置的库选项卡中后,我怀疑这些类不可见,所以我直接使用了未编译的java类。我仍然得到了
ClassNotFoundException
,尽管我并不真正理解。如果我正确使用源文件,就不会发生这种情况?这些类最终将与导出的jar中的其余代码一起压缩,对吗?
/*
  Part of the Processing project - http://processing.org

  Copyright (c) 2008 Ben Fry and Casey Reas

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software Foundation,
  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

package com.transformers.supermangletron;


import java.awt.Color;
import java.awt.Dimension;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import processing.core.PApplet;
import processing.app.Editor;
import processing.app.tools.Tool;
//import processing.app.legacy.PApplet;

/**
 * Example Tools menu entry.
 */
public class Mangler implements Tool {
  private Editor editor;

  public void init(Editor editor) {
    this.editor = editor;
  }

  private void setupSketch(){
    int w = 255;
    int h = 255;

//      PApplet ui = new PApplet();
    TestApp ui = new TestApp();

      JFrame window = new JFrame(getMenuTitle());
      window.setPreferredSize(new Dimension(w,h+20));

    window.add(ui);
      window.invalidate();
      window.pack();
      window.setVisible(true);
      window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      ui.init();

    System.out.println("setup complete");
  }

  public String getMenuTitle() {
    return "Mangle Selection";
  }


  public void run() {
      setupSketch();
  }

}
package com.transformers.supermangletron;

import processing.core.PApplet;

public class TestApp extends PApplet {
    public void setup(){
        size(100,100);
    }
    public void draw(){
        background((1.0f+sin(frameCount * .01f)) * 127);
    }
}