I am trying to create and run a Java program from the Windows XP CMD line, which is failing, doing the following is. Can anyone tell me what is wrong / what to try?
C: \ & gt; Java Version Java Version "Lk6k0_24" Java (TM) SE Runtime Environment (build Lk6k0_24-B07) Java HotSpot (TM) Client VM (build 19.1-B02, mixed mode) C: \ & gt; Mkdir c: \ j \ C: \ & gt; CD's: \ j \ c: \ j \ & gt; Notepad Testkjawa('d Notepad opens where I insert the following text and save it, then I can stop.)
public class Test {public static void Main (string [] args) {System.out.println ("hi"); }}
c: \ j \> gt; Javac test.java C: \ j \ & gt; Source Java Test Exception "main" java.lang.NoClassDefFoundError: java.lang.ClassNotFoundException: Test java.net.URLClassLoader $ 1.run (Unknown Source) at java.security.AccessController.doPrivileged due to testing (Native method) JavaknetkURLClassLoaderkfindClass (unknown source java.lang.ClassLoader.loadClass) on JavaklangkClassLoaderkloadClass (unknown source) at sun.misc.Launcher $ AppClassLoader.loadClass (unknown source) (source unknown ) The main section could not be found: The examination program will exit
The real issue is that when I am with Eclipse If I try to debug a project, I get an error that it could not "create a Java Virtual Machine", and I am trying to compile and test. ;
Update: You are right that CLASSPATH is set on my machine, yet I still get the exception to execute the suggested line:
C: \ j> Java-cp Test exception in the form "main" java.lang.NoClassDefFoundError: test (wrong name: test) java.lang.ClassLoader at java.lang.ClassLoader.defineClassCond java.lang.ClassLoader.defineClass1 (Native Method) (unknown source) on java.net at .defineClass (java.security.SecureClassLoader.defineClass (unknown source java.net.URLClassLoader.defineClass on java.net.URLClassLoader.access $ 000 unknown source)) (unknown source) (unknown source). URLClassLoader $ 1 java.security.AccessController.doPrivileged (Native method java.net.URLClassLoader.findClass on java.lang.ClassLoader.loadClass (unknown source) at .run) ((unknown source unknown source)) su N.misc.Launcher $ AppClassLoader. Java.lang.ClassLoader.loadClass (unknown source) main section could not be found on .logClass (unknown source): Examination. The program will exit
It looks like the CLASSPATH environment variable was set on your machine , And the value does not include the traditional "dot" (.) To represent the current directory. You can tell Java to see the current directory like this:
java -cp test
(This is the Java Space Dash CP Space Dot Space Test).
Comments
Post a Comment