Jump to content

Java Programming - Help needed for Novice


D2J

Recommended Posts

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 :huh:

Link to comment
Share on other sites

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

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

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

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.