Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Tokiko

[java] Cannot compile

This topic is 5211 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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."); } }

Share this post


Link to post
Share on other sites
Advertisement
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!

Share this post


Link to post
Share on other sites
Okay, sorry I understand now. For some reason it wouldn''t run, but now it does.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!