Results 1 to 7 of 7
- 04-15-2010, 03:03 AM #1
Member
- Join Date
- Apr 2010
- Posts
- 5
- Rep Power
- 0
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.
- 04-15-2010, 03:09 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Do that Eclipse people doesn't have a proper solution for that?
- 04-15-2010, 03:21 AM #3
Member
- Join Date
- Apr 2010
- Posts
- 5
- Rep Power
- 0
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.
- 04-15-2010, 03:30 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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.
-
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.
- 04-15-2010, 03:44 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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.
- 04-15-2010, 03:50 AM #7
Member
- Join Date
- Apr 2010
- Posts
- 5
- Rep Power
- 0
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
-
Exception in thread "main" java.lang.NoClassDefFoundError
By bhupal4all in forum New To JavaReplies: 12Last Post: 06-06-2012, 09:04 AM -
Class is there but NoClassDefFoundError
By jallmer in forum NetBeansReplies: 7Last Post: 11-19-2009, 03:37 AM -
Exception in thread "main" java.lang.NoClassDefFoundError: client
By fithous in forum New To JavaReplies: 1Last Post: 04-02-2009, 09:50 PM -
Using Eclipse IDE:java.lang.NoClassDefFoundError: main
By Ms.Ranjan in forum New To JavaReplies: 6Last Post: 12-12-2008, 10:17 PM -
Exception in thread "main" java.lang.NoClassDefFoundError: client Help
By b000m in forum New To JavaReplies: 6Last Post: 08-18-2008, 06:44 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks