I am able to compile the java program but not able to run a java program
When I run the java program it gives following error:
Exception in thread "main" java.lang.NoClassDefFoundError: check
Caused by: java.lang.ClassNotFoundException: check
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessContro开发者_运维百科ller.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: check. Program will exit.
The source code is:
import java.io.*;
class check {
public static void main (String [] args)
{
System.out.println("Hello");
}
}
~
~You've got the CLASSPATH
environment variable set, and it doesn't include .
(dot), the current directory. Try this
java -cp . check
(That's java space dash cp space dot space check).
Please try by set the class path first then compile and execute the class Then your problem will be resolved.
For example at command prompt:
C:\> setclasspath=%classpath%;.;
C:\> javac check.java
C:\> java check
Now, you will get the output as Hello
.
精彩评论