正确导入上述类并在其目录中查看它后,为什么会得到ClassNotFoundExpection? [英] Why am I getting ClassNotFoundExpection when I have properly imported said class and am looking at it in its directory?
问题描述
这是我的Javac编译语句:
This is my Javac compiling statement:
javac -cp
C:\java\code\ j3D\j3dcore.jar; C:\java\code\j3D\j3dutils.jar; C:\java\code\j3D\vecmath.jar
Simple.java
javac -cp "C:\java\code\j3D\j3dcore.jar;C:\java\code\j3D\j3dutils.jar;C:\java\code\j3D\vecmath.jar" Simple.java
- 编译没有问题。
- jar文件正确位于引用位置
三个jar文件( j3dcore
, j3dutils
和 vecmath
)是我程序的必需jar(或者至少根据关于J3D的官方教程
The three jar files (j3dcore
, j3dutils
, and vecmath
) are the essential jar's for my program (or at least I am led to believe according to this official tutorial on J3D
为记录起见,我从上面的pdf文件中几乎逐行删除了这段代码。
For the record I ripped this code almost line from line from the above pdf file.
当我运行我的 Simple
程序时,( java Simple
)我得到了
When I run my Simple
program, (java Simple
) I am greeted with
线程 main j中的异常ava.lang.NoClassDefFoundError:
javax / media / j3d / Cavas3d原因: java.lang.ClassNotFoundExpection:
javax.media.j3d.Canvas3D
当前,我直接盯着位于内的此
Canvas3D.class
j3dcore.jar\javax\media\j3d\
Currently I am staring directly at this Canvas3D.class
that is located within j3dcore.jar\javax\media\j3d\
wtfisthis.jpg
wtfisthis.jpg
这是源代码:
//First java3D Program
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.event.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.ColorCube;
import javax.media.j3d.*;
import javax.vecmath.*;
import java.awt.GraphicsConfiguration;
public class Simple extends Applet {
public Simple() {
setLayout(new BorderLayout());
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
Canvas3D canvas3D = new Canvas3D(config);
add("Center", canvas3D);
BranchGroup scene = createSceneGraph();
scene.compile();
// SimpleUniverse is a Convenience Utility class
SimpleUniverse simpleU = new SimpleUniverse(canvas3D);
// This moves the ViewPlatform back a bit so the
// objects in the scene can be viewed.
simpleU.getViewingPlatform().setNominalViewingTransform();
simpleU.addBranchGraph(scene);
} // end of HelloJava3Da (constructor)
public BranchGroup createSceneGraph() {
// Create the root of the branch graph
BranchGroup objRoot = new BranchGroup();
// Create a simple shape leaf node, add it to the scene graph.
// ColorCube is a Convenience Utility class
objRoot.addChild(new ColorCube(0.4));
return objRoot;
}
public static void main(String args[]){
Simple world = new Simple();
}
}
- 我正确导入了?
- 我在Javac语句中错误地引用了我的jar文件吗?
- 如果我清楚地看到了
Canvas3D
在其正确目录内为何java找不到它? -
j3dcore.jar
和<$ c $的第一个文件夹c> vecmath.jar 是 javax。 - 如果编译器感到困惑,当在源代码中引用
时如何指定确切的类?
- Did I import correctly?
- Did I incorrectly reference my jar files in my Javac statement?
- If I clearly see
Canvas3D
within its correct directory why cant java find it? - The first folder in both
j3dcore.jar
andvecmath.jar
is "javax". Is the compiler getting confused? - If the compiler is getting confused how do I specify where to find that exact class when referencing it within my source code?
推荐答案
尝试:
java -cp "C:\java\code\j3D\j3dcore.jar;C:\java\code\j3D\j3dutils.jar;C:\java\code\j3D\vecmath.jar" Simple
您需要在<$ c上包括类路径$ c> java 命令行。
这篇关于正确导入上述类并在其目录中查看它后,为什么会得到ClassNotFoundExpection?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!