I have a Swing application running on Java 1.6.0_20 on Windows XP (32-bit). I would like to publish the application via Citrix 3.0, running on Windows Server 2003. When attempting to run the client jar (with the same JRE and parameters as on XP, which works fine) from the server, however, the following exception is thrown:
Exception: java.lang.NullPointerException
Thu May 17 18:52:09 GMT 2011
java.lang.NullPointerException
at com.sun.java.swing.plaf.windows.WindowsRadioButtonUI.installDefaults(Unknown Source)
at com.sun.java.swing.plaf.windows.WindowsCheckBoxUI.installDefaults(Unknown Source)
at javax.swing.plaf.basic.BasicButtonUI.installUI(Unknown Source)
at javax.swing.JComponent.setUI(Unknown Source)
at javax.swing.AbstractButton.setUI(Unknown Source)
at com.company.aqqs.displayproject.factory.ToggleFieldFactory.newToggleField(ToggleFieldFactory.java:70)
at com.company.aqqs.displayproject.factory.ToggleFieldFactory.newToggleField(ToggleFieldFactory.java:120)
at com.company.aqqs.displayproject.factory.ToggleFieldFactory.newToggleField(ToggleFieldFactory.java:156)
at com.company.aqqs.ui.MainWindow.getqq_FreezeWindow(MainWindow.java:7546)
at com.company.aqqs.ui.MainWindow.getqq_GridFie开发者_运维技巧ld131657(MainWindow.java:7588)
at com.company.aqqs.ui.MainWindow.getqq_RefreshPaneGridField(MainWindow.java:7640)
at com.company.aqqs.ui.MainWindow.getqq_ToolbarGridField(MainWindow.java:8085)
at com.company.aqqs.ui.MainWindow.getqq_MainGrid(MainWindow.java:11228)
at com.company.aqqs.ui.MainWindow.getForm(MainWindow.java:11303)
at com.company.aqqs.ui.MainWindow.initialize(MainWindow.java:11328)
at com.company.aqqs.ui.BaseWindow.<init>(BaseWindow.java:109)
at com.company.aqqs.ui.ExWindow.<init>(ExWindow.java:281)
at com.company.aqqs.ui.MainWindow.<init>(MainWindow.java:435)
at com.company.aqqs.ui.MainWindow.launch(MainWindow.java:11544)
at com.company.aqqs.ui.MainWindow.main(MainWindow.java:11557)
Is there something missing in Windows Server 2003 that would cause the NullPointerException to be thrown and, equally important, is there a workaround?
I have a hunch that this has to do with the supported Look and Feel on each platform, and Windows Server 2003 does not fully support the Default Look and Feel that the Java VM employs.
You set the look and feel programmatically in this way
/* Choose one of the L&Fs below. */
public static void main(String[] args) {
try {
// 1. Set System L&F
UIManager.setLookAndFeel(
UIManager.getSystemLookAndFeelClassName());
// 2. or set cross-platform Java L&F (also called "Metal")
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
}
catch (UnsupportedLookAndFeelException e) {
// handle exception
}
catch (ClassNotFoundException e) {
// handle exception
}
catch (InstantiationException e) {
// handle exception
}
catch (IllegalAccessException e) {
// handle exception
}
new SwingApplication(); //Create and show the GUI.
}
Likely, to specify the Look and Feel explicitly and catch any exceptions might solve the problem. See also the Java Tutorials.
You might also want to compare the two Java Runtimes on each platform, especially the libraries in the Runtimes, i.e. .jar files.
I've seen null pointers errors like this, when Microsoft has changed something on the OS. Our Java app stops working after a Windows Update.
Updating to the latest JRE has fixed this problem the few times we've encountered it.
精彩评论