Exception in thread "main" java.lang.NoClassDefFoundError

Discussion in 'Mac Help/Tips' started by pnz999, Jan 31, 2003.

  1. pnz999 macrumors member

    Joined:
    Nov 6, 2002
    #1
    java error in mac os x.2.3 terminal.

    I get this error "Exception in thread "main" java.lang.NoClassDefFoundError" when I try to run my *.class file under Terminal? What should I do?

    I think I compile it correctly cause it pop up a *.class file with no error comment

     
  2. cubist macrumors 68020

    Joined:
    Jul 4, 2002
    Location:
    Muncie, Indiana
    #2
    Here are the correct commands to use. Note that on the "java" command, which runs the .class file, you do NOT specify "circle.class":

    javac circle.java
    java circle

    The program works. However, this is not really a good way to do things, partially using Swing and partially using text input-output. After it displays its output, you have to break (with ctrl-C) to get back to the system prompt.

    What I usually do is have main just construct the outer class:

    public static void main( String args[] ) {
    circle c = new circle();
    }

    Then have the constructor for class circle do all the work:
    public circle() {
    etc.
    }

    But Swing requires a little more complexity in application design. Keep learning!
     
  3. macktheknife macrumors 6502a

    macktheknife

    Joined:
    Jan 24, 2002
    #3
    I ran your program just fine. After you've compiled it, type the following (without the quotes): "java circle". Don't put ".class" after "circle."

    It should work--let me know if it doesn't.
     
  4. pnz999 thread starter macrumors member

    Joined:
    Nov 6, 2002
    #4
    It work! Thanks

    I just need to be in the same directory as my *.java and *.class files.


    BTW, is it possible to do C++ programming in a mac? can i still use Terminal?

    and also How can I tell what version of Java in on my machine(10.2.3 / G4 MDD)? and Java on a Mac is the same as Sun's Java?

    cause current Sun's Java version is 1.4.1_01
     
  5. bousozoku Moderator emeritus

    Joined:
    Jun 25, 2002
    Location:
    Gone but not forgotten.
    #5
    You can definitely do C++ programming within the terminal.

    type cc -o programmefile programsource for C, C++, and Objective-C.

    Then, once it compiles successfully, you may run your programme by typing ./programmefile
     
  6. macktheknife macrumors 6502a

    macktheknife

    Joined:
    Jan 24, 2002
    #6
    Yes you can. Check out this thread for more info:

    C++ Programming on OS X

    Type (again, without the quotes) "java -version" in Terminal. OS 10.2.3 currently comes with Java 1.3.1. Apple currently has a beta version of Java 1.4 for OS X, and it should hopefully be released soon.
     

Share This Page