Why am I getting ClassNotFoundExpection when I have properly imported said class and am looking at it in its directory?

↘锁芯ラ 提交于 2019-12-10 19:55:14

问题


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

  • compiles with no problems.

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

For the record I ripped this code almost line from line from the above pdf file.

  • jar files are correctly located in referenced locations

When I run my Simple program, (java Simple) I am greeted with

Exception in thread "main" java.lang.NoClassDefFoundError: javax/media/j3d/Cavas3d Caused by: java.lang.ClassNotFoundExpection: javax.media.j3d.Canvas3D

Currently I am staring directly at this Canvas3D.class that is located within j3dcore.jar\javax\media\j3d\

wtfisthis.jpg

Here is the source code:

//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();
    }
}
  1. Did I import correctly?
  2. Did I incorrectly reference my jar files in my Javac statement?
  3. If I clearly see Canvas3D within its correct directory why cant java find it?
  4. The first folder in both j3dcore.jar and vecmath.jar is "javax". Is the compiler getting confused?
  5. If the compiler is getting confused how do I specify where to find that exact class when referencing it within my source code?

回答1:


try:

java -cp "C:\java\code\j3D\j3dcore.jar;C:\java\code\j3D\j3dutils.jar;C:\java\code\j3D\vecmath.jar"  Simple

you need to include the classpath on the javacommandline as well.




回答2:


Just doing java simple wont help. You need to put all those jars in classpath while you run the program. Just like you did to compile it.

java -cp C:\java\code\j3D\j3dcore.jar;C:\java\code\j3D\j3dutils.jar;C:\java\code\j3D\vecmath.jar Simple

Please Check Setting the class path



来源:https://stackoverflow.com/questions/10827452/why-am-i-getting-classnotfoundexpection-when-i-have-properly-imported-said-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!