Exception in thread "main" java.lang.NoClassDefFoundError

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

  1. pnz999 macrumors member

    Nov 6, 2002
    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

    Jul 4, 2002
    Muncie, Indiana
    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() {

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


    Jan 24, 2002
    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

    Nov 6, 2002
    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

    Jun 25, 2002
    Gone but not forgotten.
    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


    Jan 24, 2002
    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