• Post Reply Bookmark Topic Watch Topic
  • New Topic

Cannot figure out what I forgot to set, or I set wrong, or forgot to install?  RSS feed

 
Dj Driver
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
--My Path variable has 'C:\Program Files\Java\jdk1.6.0_21\bin' in it
--My classpath is set to 'C:\Program Files\Java\jre1.6.0._01\lib\ext\QTJava.zip'

--The code I am running is fairly small and from the book Head First Java 2nd edition Covers Java 5.0:



I can compile it with no errors by typing the following:

C:\Users\Douglas\HeadFirstJava\Chapter12>javac SimpleGui1B.java

But when I try the following I get the following errors:

C:\Users\Douglas\HeadFirstJava\Chapter12>java simpleGui1B
Exception in thread "main" java.lang.NoClassDefFoundError: simpleGui1B (wrong na
me: SimpleGui1B)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
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)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

Is there an environment variable I have set wrong: path or classpath?
Have I forgot to download an install something?
I have run dozens of javac compiles and only a few have resulted in the above errors. Any suggestions would be greatly appreciated. I have googled classpath and I think I have the path and environment variables set correctly.

[Edit - added code tags - MB]

 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using "java simpleGui1B" when the real class name starts with a capital letter?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The CLASSPATH environment variable is essentially useless. And some programs that have no business messing with it change it when they're installed--like QuickTime.

If CLASSPATH is set, and if you don't supersede it with a -cp or -classpath argument on the command line, that's where the JVM will look for classes (plus a jar file or 3 that it finds relative to the Java installation). Since your class is not in QTJava.zip, it's not found.

You need to tell the JVM where to look for classes--in particular, your class--explicitly at startup time.



The "-cp ." part says, "use the current directory as the classpath".
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!