Click to See Complete Forum and Search --> : Compiles but java.lang.NoClassDefFoundError when I try to run it
manavo11
Oct 22nd, 2004, 03:17 PM
When I compile my code, I do this :
C:\Program Files\Java\jdk1.5.0\bin>javac c:\java\hello.java
But when I go to run the class file I get the following error :
C:\Program Files\Java\jdk1.5.0\bin>java c:\java\hello
Exception in thread "main" java.lang.NoClassDefFoundError: c:\java\hello
The code I have made (very advanced :D ):
class Hello {
public static void main(String [] args) {
System.out.println("Hello world");
}
}
Any ideas?
Thanks :)
brown monkey
Oct 22nd, 2004, 09:53 PM
Originally posted by manavo11
The code I have made (very advanced :D ):
:D Just got mine running.
I suggest you put the directory of your java exes to your Path Environment Variables. By this, you can javac, java on all directories you are in.
edit: Or just set your classpath to c:\java and simple java Hello.
CornedBee
Oct 25th, 2004, 07:01 PM
Usage:
java [options] classname
"c:\java\hello" is not the classname, it's the path of your class file with the .class stripped. That's different, very different.
Correct would be
java -classpath="%CLASSPATH%;c:\java\" hello
manavo11
Oct 26th, 2004, 03:19 PM
And %CLASSPATH% being the enviromental variable? How do I set that? I create it myself?
Dillinger4
Oct 26th, 2004, 03:45 PM
I dont know what os you are running but since i am running win98 i just open the System Configuration Editor and change the AutoExec.bat file.
brown monkey
Oct 26th, 2004, 08:33 PM
Originally posted by manavo11
And %CLASSPATH% being the enviromental variable? How do I set that? I create it myself?
I'm guessing you are using 2000, which I don't know. Hehehe. This is what I did in my XP time machine.
- Right click My Computer then Properties
- Advanced Tab
- Environment Variables
- System Variables then New
- Variable name: classpath, Variable value: c:\java;some_directory...
- Ok, Ok then Ok. :bigyello:
Hope this helps. If not, sorry.
manavo11
Oct 27th, 2004, 03:55 AM
I have XP so I'll try what you said BM :) Thanks :)
manavo11
Oct 29th, 2004, 05:03 PM
Originally posted by brown monkey
I'm guessing you are using 2000, which I don't know. Hehehe. This is what I did in my XP time machine.
- Right click My Computer then Properties
- Advanced Tab
- Environment Variables
- System Variables then New
- Variable name: classpath, Variable value: c:\java;some_directory...
- Ok, Ok then Ok. :bigyello:
Hope this helps. If not, sorry.
Hmmm, is version 5 needed?
Registry key 'Software\JavaSoft\Java Runtime Environment\CurrentVersion'
has value '1.4', but '1.5' is required.
Error: could not find java.dll
Error: could not find Java 2 Runtime Environment.
brown monkey
Oct 29th, 2004, 08:58 PM
I don't know if this helps but did you install the Java Runtime? You have the sdk 1.5 and you are using the Runtime 1.4. It requires the 1.5 Runtime, I guess.
manavo11
Oct 30th, 2004, 02:36 PM
Actually I don't know what I am doing :( I had installed version 5, then my teacher gave me 1.4.2 to use so I don't even know what I have anymore :(
System_Error
Oct 30th, 2004, 03:55 PM
What is your classpath environment variable set to? If you have already set it, and you think it's correct but it's still not running the program, you can usually add .;%classpath%.; at the begining of your classpath and it will work.
manavo11
Nov 1st, 2004, 04:18 AM
Thanks :) I'll try it when I get home :)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.