1

I have a class that uses Java3D that successfully compiles, although when I try to run it it says: Exception in thread "main" java.lang.NoClassDefFoundError: javax/media/j3d/Canvas3D,

With the following stack trace:

        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
        at java.lang.Class.getMethod0(Unknown Source)
        at java.lang.Class.getMethod(Unknown Source)
        at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: javax.media.j3d.Canvas3D
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)

Stuff I have already tried:

  1. I couldn't even get it to compile until I copied the Java3D jars into /jre/lib/ext/.

  2. I have the latest Java, Java3D and I am using Notepad++ and I have tried reinstalling Java3D.

  3. I have set the classpath/path correctly.

  4. There are no errors in the code.

  5. I can run normal Java applications I have created.

  6. I have tried using the classpath thing when running the application (java -classpath blahblah ApplicationName).

  7. I have checked inside the jars and the classes (including Canvas3D) are definitely in there.

Benjamin Gruenbaum
  • 270,886
  • 87
  • 504
  • 504

1 Answers1

0

Not everything you say is true.

IF the classes are in the jars, and IF you have set the classpath correctly, THEN you would not get this message.

I suspect you have a build path confused with a classpath (which is mostly associated with runtime, where build path is associated with compile time). Without knowing more details of your runtime environment, it's hard to be more specific.

It always puzzles me how someone with a problem they cannot solve asserts so definitely that all these things are set up "correctly": how do you know? Isn't the problem some evidence to the contrary, at least enough for a small doubt?

arcy
  • 12,845
  • 12
  • 58
  • 103
  • I have put the location of the Java3D jars (multiple locations) into the classpath and path environment variables, and I am fairly positive they are correct. What specifically do you need to know about my runtime environment? I would give you any details I have, but I'm unsure what you would need. Biswajit, I did use Eclipse, although I have now stopped using it. I'm using Notepad++ instead because it doesn't do that annoying auto-completion thing. Also, thanks Benjamin Gruenbaum for making my post look better. –  Mar 14 '13 at 19:53
  • (sigh) We hardly have enough information to know what to ask. You mention notepad, so you're on a command line interface? In that case, we need the OS, the default directory, locations of source and class files, value of classpath, and the lines that spill out with the NoClassDefError at the top. In short, we need to know the environment you are running and what happens, in detail, as it happens, not your interpretation of it with assertions that all of this is correct. – arcy Mar 14 '13 at 20:17
  • Sorry if I appeared arrogant, I just believed that I had done everything that was required. Yes, I'm using the command prompt on Windows 7 64Bit Home Premium. I'm unsure what you mean by "default directory", although I am going to assume you mean the location where Java is installed, which is "C:\program files(x86)\java\", Java 7, Java3D and the JRE are installed there. I have the class file and Java file in a folder on my desktop with a copy of the CMD which I use because it's easier. The "lines that spill out" are found above in my question. I will comment again as I have no characters left. –  Mar 14 '13 at 21:11
  • The value of the classpath: .;C:\Program Files (x86)\Java\jre6\bin\;C:\Program Files (x86)\Java\jre7\lib\ext\QTJava.zip;C:\Program Files (x86)\Java\Java3D\1.5.1\bin\;C:\Program Files (x86)\Java\Java3D\1.5.1\lib\ext\;C:\Program Files (x86)\Java\jdk1.6.0_22\jre\lib\ext\ (I can't do the formatting on here btw) What I do to encounter the error: I load up CMD.exe, type in "javac ", it successfully compiles, then I type "java ", it then shows the error above. Thanks. –  Mar 14 '13 at 21:16
  • and in what folder is the .jar file containing canvas3d? or do you have its class file somewhere? you seem to have a jre6 runtime and a QTJava library under a jre7 runtime; that's at least confusing and possibly problematic (if the library depends on java7, you don't want java6 in that path). also, the QTJava is a zip file; though you COULD name your .jar file that way, I'd be suspicious that it is NOT a jar, but in fact is a zip file that CONTAINS a jar instead. You might look at its contents; if it contains a .jar, that could be your problem. – arcy Mar 14 '13 at 21:17
  • To be exact, Canvas3D is found at: "C:\Program Files (x86)\Java\Java3D\1.5.1\lib\ext" -> j3dcore rar file -> "javax\media\j3d\Canvas3D.class". I'll remove Java 6 from the classpath now. I don't even have it installed. –  Mar 14 '13 at 21:22
  • when you use a command line, you are necessarily "in a directory", ie, if you enter the command "pwd" or "cd", it will show you a directory. Many (many) commands, including javac and java, use that directory as a starting point for operation. If you enter "javac A.java", it expects A.java to be in that directory. It is called your "default directory". – arcy Mar 14 '13 at 21:27
  • I have never seen a RAR file that was a jar; it is almost certainly a compressed file that contains your jar. You can download an equivalent zip file and uncompress it with windows, or get a RAR unpacker and uncompress it that way, but you need the .jar file in the classpath, not a compressed file that contains a jar. Also, you have to have the jar file name in the classpath, not the directory where the jar file lives. – arcy Mar 14 '13 at 21:30
  • The CMD.exe is in the same folder as my class and java file, which is on my desktop. I have installed JRE 7, yet it makes no difference (I also added JRE 7 to the classpath). Also, in my previous comment I said "j3dcore rar file", I was meant to say jar file. It is not a rar file. –  Mar 14 '13 at 21:35
  • I've now got the latest JDK and JRE (both 64bit), it starts loading, then I get this error: Exception in thread "main" java.lang.UnsatisfiedLinkError: no j3dcore-ogl in java.library.path at java.lang.ClassLoader.loadLibrary(Unknown Source) at java.lang.Runtime.loadLibrary0(Unknown Source) at java.lang.System.loadLibrary(Unknown Source) at javax.media.j3d.NativePipeline$1.run(NativePipeline.java:231) at java.security.AccessController.doPrivileged(Native Method) –  Mar 14 '13 at 21:57
  • You need only one of jre and jdk. jdk includes the jre. I *think* the error means there is a DLL (windows library file, native, not java) required by a java routine you've called (makes sense for a 3d library), and you must have that DLL on whatever java.library.path is. It does NOT matter where CMD.EXE is (it must be on the path), default directory is associated with the CMD window you are using to enter commands. – arcy Mar 15 '13 at 02:49
  • I added the location of j3dcore-ogl.dll to the classpath environment variable and it now works. Thank you for your help. –  Mar 15 '13 at 16:28