Search code examples
javaswingnoclassdeffounderror

NoClassDefFoundError for inner class


So, I've discovered that this is a very common problem for new Java programmers. Yet today is the first time I've run into it, after eight months of programming in Java.

This program has been working perfectly well for quite some time now. I made a minor tweak to the Swing layout last night and finally had a chance to give it a try this morning when I got that error. The tweak I made could un-made, but I am fairly certain it is unrelated to this error.

The error tells me that it occurs at the line:

private CheckTreeTableSelectionListener selectionListener = new CheckTreeTableSelectionListener();

which resides in the field list at the top of the class. Here's the interesting bit: CheckTreeTableSelectionListener is an inner class. It is not external nor being imported. Also, I did not touch that inner class last night, nor did I touch the field that creates a new instance of it. Now I understand (barely) that the NoClassDefFoundError message means that the class definition could be found at compile-time, but not at runtime. This does not really help. If it is an inner class, how can it not be found? It's right there, inside the class that instantiates it!

Edit

As requested, here is the stacktrace:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: info/chrismcgee/sky/Scheduling$CheckTreeTableSelectionListener
at info.chrismcgee.sky.Scheduling.<init>(Scheduling.java:165)
at info.chrismcgee.sky.Scheduling$2.run(Scheduling.java:204)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:744)
at java.awt.EventQueue.access$400(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:697)
at java.awt.EventQueue$3.run(EventQueue.java:691)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:714)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: java.lang.ClassNotFoundException: info.chrismcgee.sky.Scheduling$CheckTreeTableSelectionListener
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 16 more

Solution

  • In Eclipse IDE sometime some class magically disappear. You can try Project -> Clean to rebuild all.