PDA

View Full Version : Java problems




roberts
Feb 6, 2006, 03:29 PM
I'm having some trouble with Java. I can't get the first example code in a book I have to run. It compiles fine using javac on the command line, but when I run it (again on the command line), I get:

java.lang.NoClassDefFoundError

I did some googling and found that this happens because of Classpath problems, but I have no idea what that means or how to fix it...if anyone could help me that would be great.

Thanks.



stridey
Feb 6, 2006, 03:36 PM
I'm having some trouble with Java. I can't get the first example code in a book I have to run. It compiles fine using javac on the command line, but when I run it (again on the command line), I get:

java.lang.NoClassDefFoundError

I did some googling and found that this happens because of Classpath problems, but I have no idea what that means or how to fix it...if anyone could help me that would be great.

Thanks.

Are you sure you're trying to run it correctly? IIRC, that's also the error you get if you add the extension. So it should be


javac foo.java
java foo

without the .java when you run it.

jeremy.king
Feb 6, 2006, 03:44 PM
Post your source and your terminal session for review...

Eraserhead
Feb 6, 2006, 03:56 PM
you need to make sure the class inside the file has the same name as the file... eg if the class inside the java file is called 'Fraction' (the bit where it says 'public class Fraction {' would need to be called Fraction.java before compiling it.... you replace Fraction with the name of the class you are making...

PS
I would give XCode a shot too for java development... I am a complete beginner but find it really useful

roberts
Feb 6, 2006, 04:23 PM
I feel very silly...I was doing

java Hello.class

When I try it without the extention it works fine. Sorry to bother y'all with that.

:o

Doctor Q
Feb 6, 2006, 05:20 PM
The best problems to have are the ones that turn out to be simple to solve.