SwingUtilities.invokeLater causing NoClassDefFoundError
Hello people,
I've built two classes using the Singleton Pattern in an application. The first class contains the application's main method, and the second is intended to provide some control over the main window application. The following code works correctly for me:
publicclass AppInit{
privatestatic AppInit instance =null;
private AppInit(){
< ...do some application initialization ...>
}
privatestatic AppInit getInstance(){
if( instance ==null) instance =new AppInit();
return instance;
}
publicstaticvoid main( String[] args ){
// Initiate the app services
instance =new AppInit();
// Building and exibiting GUI
AppWindow.getInstance().showWindow();
}
}
publicclass AppWindow{
privatestatic AppWindow instance =null;
private JFrame mainWindow =null;
private AppWindow(){
< ... instantiate and configure the mainWindow ...>
}
privatestatic AppWindow getInstance(){
if( instance ==null) instance =new AppInit();
return instance;
}
publicvoid showWindow(){
this.mainWindow.setVisible(true );
}
}
But reading about Swing, I've concluded that the GUI initialization should be done by the 'event dispatcher thread', so I changed the AppInit's main method to the following:
publicstaticvoid main( String[] args ){
// Initiate the app services
instance =new AppInit();
SwingUtilities.invokeLater(new Runnable(){
publicvoid run(){
// Building and exibiting GUI
AppWindow.getInstance().showWindow();
}
} );
}
This change results in a 'NoDefClassFoundError: AppInit$1', referencing the line of the invokeLater invocation.
I'm not sure if I should post this into this forum, or into the Concurrency forum. Anyway, if someone could give some explanation, or indicate where I can get the answers over this problem, I woul really apreciate that.
Thanks,
Alexandre

