Results 1 to 4 of 4
  1. #1
    anon406239061 is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Default NoClassDefFoundError: packages and the classpath

    So i have a simple program, basically i have a ProjectileMotion.java source file that includes a class which does some simple calculation for projectiles, I compiled it into a class file, and its in a package Program.Physics.Kinematics.
    I then created a small test.java source file meant to use the ProjectileMotion class from that package, and I put this test.java file in dir Program...

    SO:
    ProjectileMotion.class is in ~/Programming/Java/Program/Physics/Kinematics
    test.java is in ~/Programming/Java/Program

    The test file imports Program.Physics.Kinematics.ProjectileMotion in its source, so i can use the unqualified names. I then compiled it:

    javac -cp ~/Programming/Java test.java

    It worked fine, but then when i try to run it:

    java test

    I get something starting like this:

    Exception in thread "main" java.lang.NoClassDefFoundError: Program/Physics/Kinematics/ProjectileMotion
    at test.main(test.java:9)
    Caused by: java.lang.ClassNotFoundException: Program.Physics.Kinematics.ProjectileMotion
    ........

    (it then lists more stuff)

    I figure I must be doing something wrong with my CLASSPATH variable, my use of Packages, or my call to java when i run it, but I've spent hours searching for an answer and haven't found one yet.

    Thanks in advance for the help.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,618
    Rep Power
    25

    Default Re: NoClassDefFoundError: packages and the classpath

    Your Program.Physics.Kinematics.ProjectileMotion class must be on the classpath for the java program to find it.
    If the Program folder is in the same folder as the test.class file and the default classpath of . (a dot) is not overridden by the CLASSPATH environment variable, the java program should be able to find it. Otherwise you need to tell the java program where it is located by using the classpath option.

  3. #3
    anon406239061 is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Default Re: NoClassDefFoundError: packages and the classpath

    Excellent! I moved my test.class up to the parent directory, so it was right above the package path and now it works.
    So I guess the problem was that I had my test.class within the package path (actually parallel with the top of it) when I tried to run it?

    Also, thank you very much for the help!

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,618
    Rep Power
    25

    Default Re: NoClassDefFoundError: packages and the classpath

    That was an easy one. Sometimes it takes much longer to get the point across.
    Glad you got it working.

Similar Threads

  1. Replies: 1
    Last Post: 05-03-2011, 03:28 AM
  2. NoClassDefFoundError
    By Josisco in forum JDBC
    Replies: 2
    Last Post: 10-30-2010, 09:07 PM
  3. noClassDefFoundError
    By imorio in forum Eclipse
    Replies: 11
    Last Post: 08-21-2010, 08:45 PM
  4. NoClassDefFoundError
    By Dbirge in forum New To Java
    Replies: 0
    Last Post: 03-16-2010, 06:01 PM
  5. Replies: 3
    Last Post: 02-12-2008, 12:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •