D2J Posted December 7, 2006 Share Posted December 7, 2006 Evening folks, Decided the other day I wanted to learn a programming language so have opted for Java and treated myself to a book. I followed the instructions, downloaded the software etc and I'm following the book to the letter but the first program I did I get the error Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld I have tried this three times I get the same message when I try to run it.. Any ideas what I should do next Link to comment Share on other sites More sharing options...
LL200 Posted December 7, 2006 Share Posted December 7, 2006 wanna post us some code to take a look at? dont be disheartened... Link to comment Share on other sites More sharing options...
D2J Posted December 7, 2006 Author Share Posted December 7, 2006 I'm not disheartened, just eager to learn This is what the book said to type in the file /* HelloWorld.java The classic first program */ public class HelloWorld { public static void main(String args[]) { System.out.println("Hello, World!"); }//end method definition }//end class definition Link to comment Share on other sites More sharing options...
LL200 Posted December 7, 2006 Share Posted December 7, 2006 class HelloWorld { public static void main(String[] args) { System.out.println("Hello World"); } } save as HelloWorld.java. Then: javac HelloWorld.java java HelloWorld Make sure you get the right case as Java is case-sensitive. Make sure you 'cd' into the correct directory before running the commands. Make sure you get a .class file after running the javac command. Link to comment Share on other sites More sharing options...
LL200 Posted December 7, 2006 Share Posted December 7, 2006 String args[] is not the same as String[] args. Thats probably your problem Link to comment Share on other sites More sharing options...
D2J Posted December 7, 2006 Author Share Posted December 7, 2006 I did that before and it didn't work and still won't, maybe its my laptop Link to comment Share on other sites More sharing options...
LL200 Posted December 7, 2006 Share Posted December 7, 2006 have you set up your classpath correctly? Link to comment Share on other sites More sharing options...
D2J Posted December 7, 2006 Author Share Posted December 7, 2006 have you set up your classpath correctly? I think so, just to make sure what should I do Link to comment Share on other sites More sharing options...
LL200 Posted December 7, 2006 Share Posted December 7, 2006 man its been so long since i played with java... either: java --classpath . HelloWorld or: set CLASSPATH=c:\wherever\i\put\my\code if you've not done the second, do the first one when you run your code. the . simply means the current directory. Link to comment Share on other sites More sharing options...
LL200 Posted December 7, 2006 Share Posted December 7, 2006 ...and i'm now beginning to wonder if String[] args is the same as String args[]... Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.