Tuesday, 6 August 2013

Can't get compiler working correctly with Java

Can't get compiler working correctly with Java

I'm currently learning Java and the use of my command prompt as a
compiler. But every time I execute the java command followed by my test
class "Hello" I get the below error messages:
Exception in thread "main" java.lang.NoClassDefFoundError: Hello (wrong
name: hello/Hello)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:792)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
Now I've checked my "CLASSPATH" environment variable and it is correct as
follows: .;C:\Program Files\Java\jdk1.7.0_25\bin; I've even tried removing
the .; from the beginning of the CLASSPATH but it didn't do anything
different. Now my javac command works just fine by creating a .class
version of my .java class. But I just can't get it to actually execute the
java command.
The name of my class is Hello so I typed javac Hello.java to compile my
file as a class file and it worked. But when I enter: java Hello is when I
get the above error messages. I've tested the program on my NetBeans IDE
that I made it in, and it works perfectly fine with no errors.
What could possibly be going on that would prevent me from executing my
java command to run a .class file?

No comments:

Post a Comment