0
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.AccessController.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. 
1
  • 1
    Don't you have a package statement to begin your class? What's your working environment? Are you compiling with Eclipse? Netbeans? Or just javac? Commented Nov 15, 2010 at 14:42

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.