简体   繁体   English

Windows Server 2003上的奇数Java Swing UI NullPointerException

[英]Odd Java Swing UI NullPointerException on Windows Server 2003

I have a Swing application running on Java 1.6.0_20 on Windows XP (32-bit). 我有一个在Windows XP(32位)上的Java 1.6.0_20上运行的Swing应用程序。 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: 我想通过运行在Windows Server 2003上的Citrix 3.0发布该应用程序。尝试从服务器运行客户端jar(使用与XP相同的JRE和参数,效果很好)时,会引发以下异常:

    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_GridField131657(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? Windows Server 2003中是否缺少某些东西会导致引发NullPointerException,并且同样重要的是,是否有解决方法?

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. 我有一个预感,这与每个平台上受支持的外观有关,并且Windows Server 2003不完全支持Java VM使用的默认外观。

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 . 另请参见Java教程

You might also want to compare the two Java Runtimes on each platform, especially the libraries in the Runtimes, ie .jar files. 您可能还想比较每个平台上的两个Java运行时,尤其是运行时中的 ,即.jar文件。

I've seen null pointers errors like this, when Microsoft has changed something on the OS. 当Microsoft在OS上进行了某些更改时,我已经看到过这样的空指针错误。 Our Java app stops working after a Windows Update. Windows更新后,我们的Java应用程序停止工作。

Updating to the latest JRE has fixed this problem the few times we've encountered it. 更新几次最新的JRE可以解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM