PDA

View Full Version : New to Java: weird main error msg


hecresper
02-08-04, 05:41 PM
Hi,

I just got the book Teach Yourself Java 2 Platfrom in 21 days, Professional Reference Edition. I typed in and compiled the following code in Notepad:

code:class Jabberwock {
String color;
String sex;
boolean hungry;

void feedJabberwock() {
if (hungry == true) {
System.out.println("Yum -- a peasant!");
hungry = false;
} else
System.out.println("No, thanks -- already ate.");
}

void showAttributes() {
System.out.println("This is a " + sex + " " + color + " jabberwock.");
if (hungry == true)
System.out.println("The jabberwock is hungry.");
else
System.out.println("The jabberwock is full.");
}

public static void main (String arguments[]) {
Jabberwock j = new Jabberwock();
j.color = "orange";
j.sex = "male";
j.hungry = true;
System.out.println("Calling showAttributes ...");
j.showAttributes();
System.out.println("-----");
System.out.println("Feeding the jabberwock ...");
j.feedJabberwock();
System.out.println("-----");
System.out.println("Calling showAttributes ...");
j.showAttributes();
System.out.println("-----");
System.out.println("Feeding the jabberwock ...");
j.feedJabberwock();
}
}



It seems straightforward enough. Except that I get the following error message after typing java Jabberwock:

Exception in thread "main" java.lang.NoClassDefFoundError: Jabberwock

The code compiles without an error message with javac Jabberwock.java

Any ideas as to what's causing the message to appear?

Also, the program compiles and runs fine within JPad. I get no error message in the Interactive window. I only get the error message when I'm in the DOS command prompt.

Thanks.

P.S.
I've checked the books web site and it does not mention that the error should turn up. Much less how to fix it.

stdunbar
02-08-04, 07:08 PM
Try to run "java -classpath . Jabberwock". That is a dot for the classpath and spaces between each of the arguments. Depending on the Java runtime environment you are using you may have to specify that. This assumes that you are running the java command from the directory that contains Jabberwock.class.


Exception in thread "main" java.lang.NoClassDefFoundError: Jabberwock

esh
02-10-04, 04:03 PM
here is a very simple IDE if you want to try it out.

http://www.jgrasp.org/

free of course.