Article:
  Building a Simple Java Application in Mac OS X
Subject:   Also having trouble with first page
Date:   2002-09-24 08:17:22
From:   anonymous2
Running 10.1.5 with December 2001 dev tools. First application compiles fine, but


[ghiscpc7:~/java/ninesquares] hanley% javac NineSquares.java
[ghiscpc7:~/java/ninesquares] hanley% java NineSquares.NineSquares
Exception in thread "main" java.lang.NoClassDefFoundError: NineSquares/NineSquares


A lot of people seem to be having this trouble. I tried fooling around with the classpath stuff, but I don't think that's it. Perhaps the author could comment on the problems a few of us seem to be having?

Full Threads Oldest First

Showing messages 1 through 1 of 1.

  • Daniel H. Steinberg photo Author's response
    2003-02-10 07:38:05  Daniel H. Steinberg | O'Reilly AuthorO'Reilly Blogger [View]

    Using what you have done. You created a directory called ninesquares inside of which you create a file called NineSquares.java. The first line of NineSquares.java should read "package ninesquares;" The case must match the name of the directory -- the package structure and the directory structure must match. To compile this file you need to be outside of the ninesquares directory. You can compile it with the command "javac ninesquares/NineSquares.java". According to your listing you have tried to compile it from inside of the ninesquares directory.


    Once you have compiled it (again continuing with your directory structure) you then must run it from outside of the ninesquares directory with the command "java ninesquares/NineSquares". This command effectively says look inside of the ninesquares directory and run the NineSquares.class file's main method.



    Daniel