Results 1 to 7 of 7
  1. #1
    dragonmage is offline Member
    Join Date
    Apr 2010
    Posts
    5
    Rep Power
    0

    Default One solution to NoClassDefFoundError for main class

    I have seen many reports of "NoClassDefFoundError" so I thought I'd post when I experienced this for the main class. I received this error when I tried to build/run immediately after a project "clean" operation.

    Here was my solution.

    System: Widnows XP, Eclipse 3.5.1, Java jdk 1.6.

    I was able to fix this problem by deleting the .classpath file in the project directory, re-configuring the project java build path properties then rebuilding/running the project. The properties configured for the project were identical to what was there before the clean operation (and what was displayed in the project properties after the clean).

    [More information: I had already deleted and recreated the .classpath (thru the IDE properties) once - after copying the project from an OSX environment.
    After encountering and fixing the problem as described above, a repeat of the <clean then build> on the Windows system did not produce the error. So, whatever the cause, this is not (reliably) reproducible for the same environment and project. ]
    Last edited by dragonmage; 04-15-2010 at 04:04 AM.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  3. #3
    dragonmage is offline Member
    Join Date
    Apr 2010
    Posts
    5
    Rep Power
    0

    Default

    you would think so. But here's the rub: I did the clean because I was changing classes and hitting the run button, expecting my changes to be compiled then run. But these particular changes were not being compiled. Which is why I did the clean and why I encountered the problem classpath problem. So there are multiple issues - basic userbility issues that I would not expect in a widely used IDE.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Hmmm, I just ask to know that. I'm not an Eclipse user. But I think those things should be handle by the IDE. Clean the project leads to an error is not good.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    I've been using Eclipse for 3 years, have had many projects and many re-builds, and have never encountered this problem. You may want to re-install Eclipse. Perhaps your code is bad, your Eclipse settings are bad, or your Eclipse install is corrupted.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Is it. Actually in any advance IDEs like Eclipse and so on this couldn't be happen. Once clean the project only thing need to be happen is that clean all the builds, like JAR and so on.

  7. #7
    dragonmage is offline Member
    Join Date
    Apr 2010
    Posts
    5
    Rep Power
    0

    Default

    Fubarable, that's a lot of 'perhapses'.
    On what basis do you suggest I should need to reinstall Eclipse?

    My post was merely for the benefit of other users as, when I encountered similar issues on an OSX environment, my searches revealed a lot of similar error reports and a few different proposed solutions. for example, in addition to mine, there these comments/suggestions (there second two are interesting as they pertain to a particularly misleading java error message problem):
    "


    1. Under the Project menu, un-check 'Build Automatically'
    2. Under the Project menu, select 'Clean'
    3. At the prompt, select 'Clean all projects'

    If that doesn't work, right-click your project in the project explorer and 'Reset java build path', then re-build and/or clean.

    If that still doesn't work, disconnect the project, reboot your machine, and try it again.



    From: Eclipse Community Forums

    NoClassDefFoundError (NCDFE) is not the same as ClassNotFoundException (CNFE),
    and it is perhaps the most poorly and confusingly named exception in the entire
    Java runtime.

    Despite the error message, it does NOT mean the class couldn't be found.
    Instead, it means that a *dependent* class couldn't be found or initialized -
    that is, TestDataRepoCreateXml was found, but it refers to some other class that
    couldn't be located. And there's no easy way to find out what that class is,
    unfortunately.

    You can read more at
    http://www.jroller.com/sjivan/entry/..._between_class notfoundexception_and_noclassdeffounderror
    ..

    Hopefully that'll help in your debugging. Most likely there's some missing jar
    on your classpath, but it's NOT the one containing your main class.


    Sanjiv Jivan's Blog
    People often tend to confuse java.lang.NoClassDefFoundError with java.lang.ClassNotFoundException however there's an important distinction. For example an exception (an error really since java.lang.NoClassDefFoundError is a subclass of java.lang.Error) like
    java.lang.NoClassDefFoundError:
    org/apache/activemq/ActiveMQConnectionFactory
    does not mean that the ActiveMQConnectionFactory class is not in the CLASSPATH. Infact its quite the opposite. It means that the class ActiveMQConnectionFactory was found by the ClassLoader however when trying to load the class, it ran into an error reading the class definition. This typically happens when the class in question has static blocks or members which use a Class that's not found by the ClassLoader. So to find the culprit, view the source of the class in question (ActiveMQConnectionFactory in this case) and look for code using static blocks or static members. If you don't have access the the source, then simply decompile it using JAD.
    On examining the code, say you find a line of code like below, make sure that the class SomeClass in in your CLASSPATH.
    private static SomeClass foo = new SomeClass();
    Tip : To find out which jar a class belongs to, you can use the web site jarFinder. This allows you to specify a class name using wildcards and it searches for the class in its database of jars. jarhoo allows you to do the same thing but its no longer free to use.
    If you would like to locate the which jar a class belongs to in a local path, you can use a utility like jarscan. You just specify the class you'd like to locate and the root directory path where you'd like it to start searching for the class in jars and zip files.
    Posted by sjivan ( Jul 06 2006, 06:10:13 PM EDT ) Permalink Comments [39]
    "

Similar Threads

  1. Replies: 12
    Last Post: 06-06-2012, 09:04 AM
  2. Class is there but NoClassDefFoundError
    By jallmer in forum NetBeans
    Replies: 7
    Last Post: 11-19-2009, 03:37 AM
  3. Replies: 1
    Last Post: 04-02-2009, 09:50 PM
  4. Using Eclipse IDE:java.lang.NoClassDefFoundError: main
    By Ms.Ranjan in forum New To Java
    Replies: 6
    Last Post: 12-12-2008, 10:17 PM
  5. Replies: 6
    Last Post: 08-18-2008, 06:44 AM

Posting Permissions

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