开发者

I am able to compile the java program but not able to run a java program

开发者 https://www.devze.com 2023-04-09 20:42 出处:网络
When I run the java program it gives following error: Exception in thread \"main\" java.lang.NoClassDefFoundError: check

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号