JSlider错误,但不知道它来自哪里

时间:2011-08-17 19:00:03

标签: java jslider

在我的程序中的某个时刻,正在生成以下错误。知道这是什么吗?

  Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at javax.swing.plaf.basic.BasicSliderUI.calculateThumbLocation(Unknown Source)
        at javax.swing.plaf.basic.BasicSliderUI.calculateGeometry(Unknown Source)
        at javax.swing.plaf.basic.BasicSliderUI$Handler.componentResized(Unknown Source)
        at java.awt.Component.processComponentEvent(Unknown Source)
        at java.awt.Component.processEvent(Unknown Source)
        at java.awt.Container.processEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$000(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
        at java.awt.EventQueue$4.run(Unknown Source)
        at java.awt.EventQueue$4.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)

1 个答案:

答案 0 :(得分:0)

在设置滑块以使用扩展BasicSliderUI的自定义ui时,我在初始化期间弹出了类似的间歇性NPE。我通过将它包装在invokeLater中来修复它们:

SwingUtilities.invokeLater(new Runnable(){
        @Override public void run() {
            slider.setUI(new CustomSliderUI(slider));
        }
    });