Dr. Axel Rauschmayer is a freelance software engineer, blogger and educator, located in Munich, Germany. Axel is a DZone MVB and is not an employee of DZone and has posted 246 posts at DZone. You can read more from them at their website. View Full User Profile

Java Quiz: What Does NoClassDefFoundError mean?

11.18.2010
| 6639 views |
  • submit to reddit
It took me a while to figure this out: NoClassDefFoundError is not the same as ClassNotFoundException.
  • ClassNotFoundException: The given class could not be found.
  • NoClassDefFoundError: The given class could be found, but something went wrong when initializing it (an interface it implemented could not be found, something went wrong in a static initializer etc.).

This article has more information.

From http://2ality.blogspot.com/2010/11/java-quiz-what-does-noclassdeffounderro.html

0
Your rating: None
Published at DZone with permission of Axel Rauschmayer, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags:

Comments

Chris Treber replied on Thu, 2010/11/18 - 6:24am

My credo is "nomen est omen" - "NoClassDefFoundError" is plain misleading.

Cosmin Mutu replied on Thu, 2010/11/18 - 7:48am

I don`t wanna be a bitch, but it was here all along (I think it`s pretty clear) : http://download.oracle.com/javase/1.4.2/docs/api/java/lang/NoClassDefFoundError.html

Cheers.

Robert Saulnier replied on Thu, 2010/11/18 - 8:17am

Here's an example where the class is not found, but you get the NoClassDefFoundError (and the ClassNotFoundException):

C:\>java -showversion NonExistingClass
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing)

Exception in thread "main" java.lang.NoClassDefFoundError: NonExistingClass
Caused by: java.lang.ClassNotFoundException: NonExistingClass
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: NonExistingClass. Program will exit.

Bruce Wallace replied on Thu, 2010/11/18 - 11:49am

This is very useful!  I recently restarted a legacy J2EE server and a web app suddenly started failing as per below. I have been scratching my head as to how some class file got deleted that was there before.  This tells me I've been barking up the wrong tree!  THANKS!

500 Internal Server Error
/GanttMagic/getImage:

javax.servlet.ServletException: null
java.lang.NoClassDefFoundError
at org.apache.batik.transcoder.image.ImageTranscoder.(Unknown Source)
at org.apache.batik.transcoder.image.JPEGTranscoder.(Unknown Source)
at com.polyglotinc.ganttmagic.ImageBuilder.emitJPG(ImageBuilder.java:185)
at com.polyglotinc.ganttmagic.ImageBuilder.emit(ImageBuilder.java:216)
at com.polyglotinc.ganttmagic.http.GetImageServlet.emit(GetImageServlet.java:185)
at com.polyglotinc.ganttmagic.http.GetImageServlet.doRequest(GetImageServlet.java:139)
at com.polyglotinc.ganttmagic.http.GetImageServlet.doGet(GetImageServlet.java:116)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at allaire.jrun.servlet.JRunSE.service(JRunSE.java:1013)
at allaire.jrun.servlet.JRunSE.runServlet(JRunSE.java:925)
at allaire.jrun.servlet.JRunRequestDispatcher.forward(JRunRequestDispatcher.java:88)
at allaire.jrun.servlet.JRunSE.service(JRunSE.java:1131)
at allaire.jrun.servlet.JvmContext.dispatch(JvmContext.java:330)
at allaire.jrun.jrpp.ProxyEndpoint.run(ProxyEndpoint.java:367)
at allaire.jrun.ThreadPool.run(ThreadPool.java:272)
at allaire.jrun.WorkerThread.run(WorkerThread.java:75

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.