user202051
user202051

Reputation: 173

NoClassDefFoundError When launching from terminal(Java)

I am getting a Exception in thread "main" java.lang.NoClassDefFoundError: start (wrong name: Start) when trying to run my program from the terminal. I have two classes in my program called Load.java and Start.java when the files compile fine using javac *.java but when I then try and launch Start.java using java Start I get this error.

Exception in thread "main" java.lang.NoClassDefFoundError: start (wrong name: Start)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)

I have found other examples of people getting similar errors but cant seem to find the solution to mine or why it is happening. So that is my question, why am i getting this error? What can I do to prevent it from happening again?

Thanks, Ciaran.

Upvotes: 1

Views: 94

Answers (2)

viswa k
viswa k

Reputation: 1

You have to open the CMD from the main path and run the java command with full package details.

Ex: If your Start.class is in C:\EampleProj\com\test\Start.class. then you should try

C:\EampleProj>java com.test.Start

Upvotes: 0

user2097804
user2097804

Reputation: 1132

You have to use the fully qualified class name. if your class Start is in package a, then you must launch using java a.Start for example. You can also use the -cp option to set Classpath.

Upvotes: 3

Related Questions