-
Exceptions in thread
Hi
I`m having a problem with my first program. In cmd I have written: javac Hallo.java , that was ok, but when I entered: java Hallo , the following message appeared:
C:\Program Files\Crimson Editor\template>java Hallo
Exception in thread "main" java.lang.NoClassDefFoundError: Hallo
Caused by: java.lang.ClassNotFoundException: Hallo
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 java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: Hallo. Program will exit.
If anybody can help I would be grateful
-
Show us the code first :)
-
The runtime is saying that it cannot locate the Hallo class (ie Hallo.class).
This is because it is not on the classpath you are using. Since you did not specify any classpath on the command line the java executable will use either the value of the CLASSPATH variable if you have one set, or the current directory.
(The classpath is just a set of locations that the java runtime will use to locate classes.)
Note (1) the runtime will not do both so if you have a CLASSPATH variable then the current directory will not be searched for classes. (2) Commonly, people don't set the CLASSPATH variable and if it is set they unset it so that it doesn't get in the road of what they want to do.
It strikes me that the template directory is an odd place for you to put your data files. (Either .java or .class files). I would suggest that you locate the Hallo.java file and move it somewhere sane: on a Windows machine this will be somewhere within the "Documents and settings" folder. Then from within the folder you move the file to you can compile and run with:
Code:
C:\Documents and Settings\UserName\JavaStuff>javac Hallo.java
C:\Documents and Settings\UserName\JavaStuff>dir
C:\Documents and Settings\UserName\JavaStuff>java Hallo
The "dir" command is just to check that Hallo.class exists where it should. If these commands prove ineffective, post the output when you run them.
-
-