Reputation: 355
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.AccessController.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");
}
}
~
~
Upvotes: 2
Views: 551
Reputation: 1
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
.
Upvotes: 0
Reputation: 81684
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).
Upvotes: 1