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
| 8143 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

 

Bruce Wallace replied on Wed, 2013/08/28 - 6:41pm in response to: Bruce Wallace

Here I am almost 3 years later with the same error as I mentioned above (except that I never wrote down what I did to fix it!!)

So, after tracking it down again, I thought I'd say what it was for the record (and when I have to solve this again in 3 years).

The error shown is just a side effect of exceptions Batik is throwing because (as is seen much earlier in my server log file), Java itself had an internal error:

java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.

...which was due to starting the J2EE server remotely via telnet, rather than locally via an x-window.  Batik uses Java APIs which only work when the jvm has access to an x-server (which it doesn't via telnet).

Comment viewing options

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