开发者

NoClassDefFoundError found!

开发者 https://www.devze.com 2023-01-24 23:20 出处:网络
import java.io.*; public class ArrayApp{ public static void main(String[] args){ System.out.println(\"lllll\");
import java.io.*;

public class ArrayApp{

    public static void main(String[] args){

        System.out.println("lllll");
    } // end main()
} // end class ArrayApp

i get this error when i run my application after compiling it.

Exception in thread "main" java.lang.NoClassDefFoundError: ArrayApp
Caused by: java.lang.ClassNotFoundException: ArrayApp
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.A开发者_开发技巧ccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: ArrayApp.  Program will exit.


You need to make sure your class file is in the classpath. Assuming you are using the default package (i.e. no package declaration), you need to tell Java where to find your class when you run it. So let's assume your ArrayApp.class file is in the same directory. You will need to run it like this:

java -cp . ArrayApp

The option -cp and the following . tell Java that the classes will be in the current directory. The longer name for -cp is -classpath, so you can use that as well.

Also note the space between the classpath and the class name. The path is the base directory of where your class files are located. If you compiled them into a directory named "bin" then you would change the way you call Java like this:

java -cp bin/ ArrayApp

The "ArrayApp" is the fully qualified class name.


Your classpath is incorrect. Try...java -classpath . ArrayApp

0

精彩评论

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