Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

roberts

macrumors newbie
Original poster
Jun 18, 2005
28
0
Scotland
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:

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

macrumors 65816
Jan 21, 2005
1,136
0
Massachusetts, Connecticut
roberts said:
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:

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

Code:
javac foo.java
java foo

without the .java when you run it.
 

Eraserhead

macrumors G4
Nov 3, 2005
10,434
12,250
UK
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

macrumors newbie
Original poster
Jun 18, 2005
28
0
Scotland
I feel very silly...I was doing

Code:
java Hello.class

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

:eek:
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.