Exception in thread "main" java.lang.NoClassDefFoundError: simple (Newbie)
Hiya, I am very new to all programming. Can anyone tell me why the below will not run? I have set the classpath in control panel and have tried setting it first in command prompt. Its probably obvious, but I cannot find the answers on other forums. The simple.class file is in the same folder as the simple.java. Have tried with and without -classpath - i get a longer error without -classpath. Thanks.
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\Scotty>javac D:\JAVA\simple.java
C:\Users\Scotty>java -classpath . simple
Exception in thread "main" java.lang.NoClassDefFoundError: simple
Caused by: java.lang.ClassNotFoundException: simple
at java.net.URLClassLoader$1.run(URLClassLoader.java: 202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.j ava:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:3 07)
at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:2 48)
Could not find the main class: simple. Program will exit.
Re: Exception in thread "main" java.lang.NoClassDefFoundError: simple (Newbie)
Where is the .class file created by the javac command? Is it in the same folder where you executed the java command?
You told the javac command where the source file was.
Re: Exception in thread "main" java.lang.NoClassDefFoundError: simple (Newbie)
Yes it is in the same folder. I have also tried just
C:\Users\Scotty>javac D:\JAVA\simple.java
C:\Users\Scotty>java simple
Exception in thread "main" java.lang.NoClassDefFoundError: simple
Caused by: java.lang.ClassNotFoundException: simple
at java.net.URLClassLoader$1.run(URLClassLoader.java: 202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.j ava:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:3 07)
at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:2 48)
Could not find the main class: simple. Program will exit.
In D:\JAVA is simple.java and simple.class
Re: Exception in thread "main" java.lang.NoClassDefFoundError: simple (Newbie)
Re: Exception in thread "main" java.lang.NoClassDefFoundError: simple (Newbie)
Quote:
In D:\JAVA is simple.java and simple.class
But you are in a different folder, not the one with the simple.class file. Here you are in the Scotty folder:
Quote:
C:\Users\Scotty>java simple
Change folders using the cd command to be in the Java folder, not the Scotty folder.
Re: Exception in thread "main" java.lang.NoClassDefFoundError: simple (Newbie)
I see what you mean, but I cannot get it to change directory. Can you give me an example? I am obliviously doing something wrong.
Re: Exception in thread "main" java.lang.NoClassDefFoundError: simple (Newbie)
Use the cd command to change directories.
cd THEDIR
or cd ..
Re: Exception in thread "main" java.lang.NoClassDefFoundError: simple (Newbie)
Sorry!
C:\Users\Scotty>cd D:\JAVA
C:\Users\Scotty>javac simple.java
javac: file not found: simple.java
Usage: javac <options> <source files>
use -help for a list of possible options
C:\Users\Scotty>javac D:\JAVA\simple.java
C:\Users\Scotty>cd D:\JAVA\
C:\Users\Scotty>java simple
Exception in thread "main" java.lang.NoClassDefFoundError: simple
Caused by: java.lang.ClassNotFoundException: simple
at java.net.URLClassLoader$1.run(URLClassLoader.java: 202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.j ava:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:3 07)
at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:2 48)
Could not find the main class: simple. Program will exit.
Re: Exception in thread "main" java.lang.NoClassDefFoundError: simple (Newbie)
What folder is the simple.class file in? Use the dir command to show what files are in the current folder.
If the simple.class file is NOT in your current folder, then the java command will not find it and you get the error.
Use the cd command to change the current folder to the one with the simple.class file. Then java simple will work.
Re: Exception in thread "main" java.lang.NoClassDefFoundError: simple (Newbie)
simple.class is in D:\JAVA
(D:\JAVA\simple.class)
Re: Exception in thread "main" java.lang.NoClassDefFoundError: simple (Newbie)
Have you tried executing the java command when you are in the JAVA folder?
Read post#9 again
Re: Exception in thread "main" java.lang.NoClassDefFoundError: simple (Newbie)
Fixed it xD. It still ignores one of my directorys though....
Re: Exception in thread "main" java.lang.NoClassDefFoundError: simple (Newbie)
If you get errors, please post them here.
Re: Exception in thread "main" java.lang.NoClassDefFoundError: simple (Newbie)
Quote:
Originally Posted by
Scotty
Sorry!
C:\Users\Scotty>cd D:\JAVA
C:\Users\Scotty>javac simple.java
javac: file not found: simple.java
Usage: javac <options> <source files>
use -help for a list of possible options
C:\Users\Scotty>javac D:\JAVA\simple.java
C:\Users\Scotty>cd D:\JAVA\
C:\Users\Scotty>java simple
Exception in thread "main" java.lang.NoClassDefFoundError: simple
Caused by: java.lang.ClassNotFoundException: simple
at java.net.URLClassLoader$1.run(URLClassLoader.java: 202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.j ava:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:3 07)
at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:2 48)
Could not find the main class: simple. Program will exit.
Hey Scotty!
--> C:\Users\Scotty>cd D:\JAVA
This line won't take u to the D:\JAVA location. Instead, it will still be in C:\Users\Scotty.
You need to first go into the D drive by giving
C:\Users\Scotty>D:
and then give the command "cd JAVA"
Now that you are in the required folder. you can directly give
"javac simple.java" followed by
"java simple"
It should solve the problem