I'm using the Netbeans 8.2 UI Builder/Designer (Matisse) and have some custom widgets. A custom widget named ChoiceTab displays a non-UI object called Choice. When I click on a class, named HL7RuleAdd, that uses ChoiceTab and click on "Design", I get the following error:
ClassDefNotFoundException:
java.lang.NoClassDefFoundError: Could not initialize class com.hcs.orc.datatype.Choice
at com.hcs.orc.detail.ChoiceTab.<init>(ChoiceTab.java:58)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at org.netbeans.modules.form.CreationFactory.createDefaultInstance(CreationFactory.java:180)
at org.netbeans.modules.form.RADComponent.createBeanInstance(RADComponent.java:252)
at org.netbeans.modules.form.RADComponent.initInstance(RADComponent.java:191)
at org.netbeans.modules.form.GandalfPersistenceManager.restoreComponent(GandalfPersistenceManager.java:780)
at org.netbeans.modules.form.GandalfPersistenceManager.loadComponent(GandalfPersistenceManager.java:968)
at org.netbeans.modules.form.GandalfPersistenceManager.restoreComponent(GandalfPersistenceManager.java:824)
at org.netbeans.modules.form.GandalfPersistenceManager.loadComponent(GandalfPersistenceManager.java:968)
at org.netbeans.modules.form.GandalfPersistenceManager.restoreComponent(GandalfPersistenceManager.java:824)
at org.netbeans.modules.form.GandalfPersistenceManager.loadComponent(GandalfPersistenceManager.java:968)
at org.netbeans.modules.form.GandalfPersistenceManager.loadForm(GandalfPersistenceManager.java:503)
at org.netbeans.modules.form.GandalfPersistenceManager.loadForm(GandalfPersistenceManager.java:283)
at org.netbeans.modules.form.FormEditor$2.run(FormEditor.java:352)
at org.netbeans.modules.form.FormLAF$2.run(FormLAF.java:293)
at org.netbeans.modules.openide.util.NbMutexEventProvider$Event.doEventAccess(NbMutexEventProvider.java:138)
at org.netbeans.modules.openide.util.NbMutexEventProvider$Event.readAccess(NbMutexEventProvider.java:98)
at org.netbeans.modules.openide.util.LazyMutexImplementation.readAccess(LazyMutexImplementation.java:94)
at org.openide.util.Mutex.readAccess(Mutex.java:250)
at org.netbeans.modules.form.FormLAF.executeWithLookAndFeel(FormLAF.java:276)
at org.netbeans.modules.form.FormEditor.loadFormData(FormEditor.java:349)
at org.netbeans.modules.nbform.FormEditorSupport.loadOpeningForm(FormEditorSupport.java:461)
at org.netbeans.modules.nbform.FormDesignerTC.loadForm(FormDesignerTC.java:279)
at org.netbeans.modules.nbform.FormDesignerTC.access$300(FormDesignerTC.java:87)
at org.netbeans.modules.nbform.FormDesignerTC$PreLoadTask$1.run(FormDesignerTC.java:268)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:159)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
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)
ChoiceTab is used in three different places, all of which have this problem and all belong to the same project.
This is strange, since com.hcs.orc.datatype.Choice is in the same project as above ChoiceTab and HL7RuleAdd. Even strange, Netbeans works correctly in one branch of my code, but fails with the error above in a different branch.
Here is the line 58 and the start of the constructor for the ChoiceTab:
public ChoiceTab() {
initComponents();
DataFieldTraits trait = Choice.getFieldTraits(ORCConstants.DI_CHOICE_MNC, Choice.dinfo.getTraitsS());
As you can see one line 58, the references to Choice are static calls to get other information about Choice.
The two branches aren't so different (recent branch), so I backed out most of the changes in the failing branch, but it didn't resolve the problem. I've looked at the IDE Log window and not found anything other than the above error.
ChoiceTab has been added to the Netbeans Designer Palette as a Container, but it doesn't seem to make a difference if it is in the Palette or not.
I've also tried a clean and building all the projects. It builds without error, but continues to fail in Netbeans.
ChoiceTab, itself, is a "designed" class and works correctly when you click the "Design" button.
Additionally, tried deleting the Netbeans cache and restarting Netbeans. This also did not solve the problem.
I've run out of ideas and would appreciate any help.
With help from a coworker, I was able to track the problem down. Long and short of it is, the Choice class has static members that are initialized on class load. These were in turn calling other static methods, one of which was returned a singleton for an abstract factory. However, the singleton was not set, since the concrete implementation is set on start up of our application (and is not available prior to that). So the factory came back as null which resulted in a NullPointerException and caused the Choice class to fail to load. This NullPointerException was then masked by the misleading ClassDefNotFoundException.
The way we tracked down the problem was to introduce static System.out.println(...) statements into the different classes being statically initialized. Combined this with commenting out some static initialization code, we were able to track down the problem.
Example of our System.out.println(...) code:
static {
System.out.println("Initializing Choice";
}
When running Netbeans from the command line and clicking the "Design" button, we could see our print statements and debug the problem.