Results 1 to 4 of 4
  1. #1
    Benjaarm is offline Member
    Join Date
    Oct 2011
    Posts
    2
    Rep Power
    0

    Default Runtime Error - NoClassDefFoundError: <wrong name ...>

    Hi All,

    I am having trouble getting a user-defined class to work properly. The java compiles just fine but I get the following runtime error: NoClassDefFoundError: HelloWorld <wrong name...> ... etc. I'm sure this is related to the classpath setting but I can't seem to work it out.

    The relevant source code in HelloWorld.java:
    Java Code:
    package examples.HelloWorld
    import com.sitename.helper.Helper;
    To the classpath variable I have added:
    Java Code:
    C:\Program Files\Java\sitename\classes\com\sitename\helper
    HelloWorld.java and HelloWorld.class are contained in:

    Java Code:
    C:\Program Files\Java\sitename\examples\HelloWorld
    The Helper.class is contained in the same directory structure as I have set in the classpath variable.

    I have searched for the info on how to figure this out but I have not found anything that is helping. I have no doubt this is a fairly common newbie error and I'm somewhat annoyed that I can't figure this out with the information I have at hand.

    I'd really appreciate your help.

    Thanks in advance,
    Ben

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,044
    Blog Entries
    7
    Rep Power
    23

    Default Re: Runtime Error - NoClassDefFoundError: <wrong name ...>

    The full name of your class is examples.HeloWorld.HelloWorld and you should run it as such (i.e. including the package name).

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  3. #3
    Benjaarm is offline Member
    Join Date
    Oct 2011
    Posts
    2
    Rep Power
    0

    Default Re: Runtime Error - NoClassDefFoundError: <wrong name ...>

    Hi JosAH,

    Thanks for your reply. Unfortunately, I am now getting "error: could not find or load main class: example.HelloWorld,HelloWorld". I get the same error no matter what variation of path or class name I use (eg example.HelloWorld).

    I will stick at it.

    Thanks,
    Ben

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,044
    Blog Entries
    7
    Rep Power
    23

    Default Re: Runtime Error - NoClassDefFoundError: <wrong name ...>

    Quote Originally Posted by Benjaarm View Post
    Thanks for your reply. Unfortunately, I am now getting "error: could not find or load main class: example.HelloWorld,HelloWorld". I get the same error no matter what variation of path or class name I use (eg example.HelloWorld).
    If your class is stored in /X/examples/HeloWorld/HelloWorld.class (X is any directory path) then your classpath variable should contain /X and you should start the class by doing:

    Java Code:
    java -cp /X examples.HelloWorld.HelloWord
    Of course you should add any other classpath components needed by your program.

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

Similar Threads

  1. runtime error
    By ashaudhaya in forum New To Java
    Replies: 2
    Last Post: 11-12-2010, 11:13 AM
  2. Runtime Error
    By mathfxr in forum New To Java
    Replies: 8
    Last Post: 09-17-2010, 08:26 PM
  3. Replies: 1
    Last Post: 04-07-2009, 10:50 AM
  4. Replies: 3
    Last Post: 01-23-2009, 09:53 AM
  5. Replies: 5
    Last Post: 09-03-2008, 05:29 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
  •