Skip to main content
gamedev.net
🔒 Locked

[java] Cannot compile

Started by Tokiko May 8, 2004 at 4:53 PM 4 replies 450+ views
Original Post
Tokiko
Tokiko
I recently got the Java SDK installed and I found a tutorial on the net about creating your first program. I put the code in notepad, saved it as MyProgram.java and ran javac. It created a class file, but when I try to compile that with java it gives me the following error: Exception in thread "main"java.lang.NoClassDefFoundError: MyProgram I have no idea what that means. Is it my source code thats causing the problem, or did I mess up when installing the SDK. Heres my source code. I dont understand it all right now, so any help is appreciated. public class MyProgram { public static void main(String[] args) { System.out.println( "Hello World."); } }
Raghar
Raghar
You should write on the screen "Wow it''s working \u3234".

-cp .

cmptrgear
cmptrgear
If it created a class file then it worked.

Stepps to compiling and running a java file

javac MyProgram.java
-this creates MyProgram.class

java MyProgram
-runs the program notice that the .class is left out

admire your creation

"Give a man a fish and he will eat for a day, drown a man in the water and the fish will eat for a week!
"Pfft, Facts! Facts can be used to prove anything!" -- Homer J. Simpson
Tokiko
Tokiko
Okay, sorry I understand now. For some reason it wouldn''t run, but now it does.
abeylin
abeylin
If your "CLASSPATH" variable is set to one version of java libraries, and you use java.exe from another version of java, you''ll get that error.

For example, say you have c:\java1.2 and c:\java1.4
And your CLASSPATH is set to c:\java1.2, but you are running: c:\java1.4\bin\java.exe - then you''ll get the error.

You can either set CLASSPATH correctly, or unset it.
For example in Cygwin/unix you do this:
unset CLASSPATH
and in DOS shell you do:
set CLASSPATH=




http://www.anywherenotes.com - never lose another note again.
Strife
Strife
Chances are, you were trying to run it by running "java MyClass.class" when instead you need "java MyClass". This is because java searches for the name of the class without regard to the extension... To be honest, I don''t know why Sun bothered making an extension, other than possibly to stay with the whole Windows-likes-extensions thing... Not sure though.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.