我在设置处理时遇到问题。我有另一个项目,它可以很好地使用它,但是当我尝试创建一个新项目时,我不断遇到错误。我已经设置了所有库,并且正在使用处理 3.5.4,尽管我也尝试过最新版本。所有内容都添加到构建路径中,所以我不明白为什么找不到 PApplet
Error: Could not find or load main class embodiedInteractionDance.MovingRectangle
Caused by: java.lang.NoClassDefFoundError: processing/core/PApplet
运行配置并单击“显示命令行”
C:\Users\user\.p2\pool\plugins\org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_17.0.9.v20231028-0858\jre\bin\javaw.exe
-Dfile.encoding=UTF-8
-Dstdout.encoding=UTF-8
-Dstderr.encoding=UTF-8
-p "C:\Users\user\eclipse-workspace\embodiedInteractionDance\libs\core.jar"
-classpath "C:\Users\user\eclipse-workspace\embodiedInteractionDance\bin;C:\Users\user\eclipse-workspace\embodiedInteractionDance\libs\gluegen-rt.jar;C:\Users\user\eclipse-workspace\embodiedInteractionDance\libs\jogl-all.jar;C:\Users\user\eclipse-workspace\embodiedInteractionDance\libs\MidPose.jar;C:\Users\user\eclipse-workspace\embodiedInteractionDance\libs\gluegen-rt-natives-windows-amd64.jar;C:\Users\user\eclipse-workspace\embodiedInteractionDance\libs\jogl-all-natives-windows-amd64.jar;C:\Users\user\eclipse-workspace\embodiedInteractionDance\libs\jogl-all-noawt-2.2.4.jar"
-XX:+ShowCodeDetailsInExceptionMessages embodiedInteractionDance.MovingRectangle
我是否正确理解这是核心 jar 的问题? 我已经清除了所有现有的运行配置并再次尝试,同样的错误
移动矩形
package embodiedInteractionDance;
import processing.core.*;
public class MovingRectangle extends PApplet{
// The argument passed to main must match the class name
public static void main(String[] args) {
PApplet.main(MovingRectangle.class.getName());
}
// method used only for setting the size of the window
public void settings(){
size(400,400);
}
// identical use to setup in Processing IDE except for size()
public void setup(){
background(0);
stroke(255);
strokeWeight(10);
}
// identical use to draw in Processing IDE
public void draw(){
line(0, 0, 500, 500);
}}
使用处理
package shapes;
import processing.core.PApplet;
public class UsingProcessing extends PApplet {
// Canvas canvas = new Canvas();
// JFrame overlay = new JFrame("Mouse Listener");
public static void main(String[] args) {
PApplet.main(UsingProcessing.class.getName());
// canvas.addMouseListener();
}
public void settings(){
size(1000,1000);
}
public void setup(){
strokeWeight(1);
//moved the static objects from draw() to here
//hair
fill(0);
ellipse(width/7*4, height/7, width-100, 350);
rect(width/7, 200, width-100,height);
//head
fill(210,180,140);
ellipse(height/2+50,width/2+50,height-100,width-100);
//eyes
fill(0);
ellipse(width/3,height/3,100,100);
ellipse(width/3*2,height/3,100,100);
}
public void draw(){
//pupils (leave them growing, fun effect)
fill(120,50,240);
stroke(0);
ellipse(width/3,height/3,second(),second());
ellipse(width/3*2,height/3,second(),second());
//nose
stroke(255, 102, 0);
strokeWeight(5);
noFill();
curve(width/2, height/2-50, width/2, height/2+100, width/2+50, height/2+100, width/2+75, height/2+150);
//eyebrows
fill(175,50,75);
triangle(width/4, height/4, width/4, height/4+50, width/4+150, height/4+50 );
triangle(width/4*3-150, height/4, width/4*3-150, height/4+50, width/4*3+100, height/4+50 );
//mouth
fill(255,50,100);
stroke(200,50,50);
arc(width/2, height/3*2, width/3*2-width/3, second(), 0, PI, CHORD);
}}
根据命令行,您的
core.jar
位于模块路径(-p
)上,而不是位于类路径(-classpath
)上。这可能是一个问题,因为模块路径上的 JAR 被视为单独的封装模块。相比之下,所有其他 JAR 都位于类路径上,因此被视为单个未封装的模块,即所谓的“未命名模块”。
在 项目 > 属性:Java 构建路径选项卡 库,通过拖放将 core.jar
从
Modulepath移动到 Classpath。