Java problems

Discussion in 'Mac Programming' started by roberts, Feb 6, 2006.

  1. macrumors newbie

    Joined:
    Jun 18, 2005
    Location:
    Scotland
    #1
    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.
     
  2. macrumors 65816

    stridey

    Joined:
    Jan 21, 2005
    Location:
    Massachusetts, Connecticut
    #2
    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.
     
  3. macrumors 603

    jeremy.king

    Joined:
    Jul 23, 2002
    Location:
    Fuquay Varina, NC
    #3
    Post your source and your terminal session for review...
     
  4. macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #4
    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
     
  5. thread starter macrumors newbie

    Joined:
    Jun 18, 2005
    Location:
    Scotland
    #5
    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:
     
  6. Administrator

    Doctor Q

    Staff Member

    Joined:
    Sep 19, 2002
    Location:
    Kepler-452b
    #6
    The best problems to have are the ones that turn out to be simple to solve.
     

Share This Page