Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    NoClassDefFoundError

    I am trying to run two different programs created by classmates, both programs compile but when I try to run them I am getting the following error:

    "Exception in thead "main" java.lang.NoClassDefFoundError: <wrong name>
    Could not find the main class"

    Both classmates insist that their programs run fine on thier computers. Also I have no porblems running my own assignment as well as assignments for other classmates.

    I did a bit of research and found on java.sun that the error is telling me the definition of the class file exists at compile time but can no longer be found.

    Is there anything that I am doing wrong? Another classmate told me to add -classpath . classname when running it from the command window but this also did not work.

    Any advice woud be appreciated. Thanks

  • #2
    Senior Coder ckeyrouz's Avatar
    Join Date
    Jun 2009
    Location
    Montreal, Canada
    Posts
    1,044
    Thanks
    5
    Thanked 179 Times in 179 Posts
    The problem is there is an incompatibility between the location where you exist in the command prompt and the hierarchy of the java packages you have.

    First of all you have to add the package to your classpath.

    I will give examples on how you can do it:
    Let's suppose that you have a folder named myclasses somewhere under C drive and in it you have the package com.mypackage and in it you have the class you need to execute , name it MyClass.

    you can call it in 2 ways:
    set your prompt at the folder c:\myclasses:
    C:\myclasses> java com.mypackage.MyClass (make sure to call the class using its full path)

    or you can be anywhere supposedly on c:\
    c:\> java -classpath c:\myclasses com.mypackage.MyClass
    here as well you need to call the java class using its full package.

    Hope this was useful to you.

  • Users who have thanked ckeyrouz for this post:

    Stephandeye (07-23-2009)


  •  

    Posting Permissions

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