Je développe une application pour une entreprise, qui gère une base de données Oracle de différentes manières. Le programme est en Java, NetBeans et il devient assez gros. Je ne dirais pas que c'est très bien écrit, mais j'ai souvent revenir à plus mauvais code plus ancien et essayer de le rendre aussi lisible et oop que je peux.Java - NullPointerException au démarrage. Bug Swing ou une mise en œuvre défectueuse?
J'ai remarqué que 1 fois sur 10, quand je commence le programme , je recevais l'exception suivante: (si le programme démarre et fonctionne bien, même ces temps)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.plaf.synth.SynthLabelUI.getMinimumSize(SynthLabelUI.java:199)
at javax.swing.JComponent.getMinimumSize(JComponent.java:1702)
at javax.swing.GroupLayout$ComponentSpring.calculateNonlinkedMinimumSize(GroupLayout.java:2933)
at javax.swing.GroupLayout$ComponentSpring.calculateMinimumSize(GroupLayout.java:2897)
at javax.swing.GroupLayout$Spring.getMinimumSize(GroupLayout.java:1315)
at javax.swing.GroupLayout$ComponentSpring.calculatePreferredSize(GroupLayout.java:2904)
at javax.swing.GroupLayout$Spring.getPreferredSize(GroupLayout.java:1325)
at javax.swing.GroupLayout$Group.getSpringSize(GroupLayout.java:1604)
at javax.swing.GroupLayout$Group.calculateSize(GroupLayout.java:1593)
at javax.swing.GroupLayout$Group.calculatePreferredSize(GroupLayout.java:1568)
at javax.swing.GroupLayout$Spring.getPreferredSize(GroupLayout.java:1325)
at javax.swing.GroupLayout$Group.getSpringSize(GroupLayout.java:1604)
at javax.swing.GroupLayout$Group.calculateSize(GroupLayout.java:1590)
at javax.swing.GroupLayout$Group.calculatePreferredSize(GroupLayout.java:1568)
at javax.swing.GroupLayout$Spring.getPreferredSize(GroupLayout.java:1325)
at javax.swing.GroupLayout$Group.getSpringSize(GroupLayout.java:1604)
at javax.swing.GroupLayout$Group.calculateSize(GroupLayout.java:1593)
at javax.swing.GroupLayout$Group.calculatePreferredSize(GroupLayout.java:1568)
at javax.swing.GroupLayout$Spring.getPreferredSize(GroupLayout.java:1325)
at javax.swing.GroupLayout$Group.getSpringSize(GroupLayout.java:1604)
at javax.swing.GroupLayout$Group.calculateSize(GroupLayout.java:1590)
at javax.swing.GroupLayout$Group.calculatePreferredSize(GroupLayout.java:1568)
at javax.swing.GroupLayout$Spring.getPreferredSize(GroupLayout.java:1325)
at javax.swing.GroupLayout$Group.getSpringSize(GroupLayout.java:1604)
at javax.swing.GroupLayout$Group.calculateSize(GroupLayout.java:1590)
at javax.swing.GroupLayout$Group.calculatePreferredSize(GroupLayout.java:1568)
at javax.swing.GroupLayout$Spring.getPreferredSize(GroupLayout.java:1325)
at javax.swing.GroupLayout$Group.getSpringSize(GroupLayout.java:1604)
at javax.swing.GroupLayout$Group.calculateSize(GroupLayout.java:1588)
at javax.swing.GroupLayout$Group.calculatePreferredSize(GroupLayout.java:1568)
at javax.swing.GroupLayout$Spring.getPreferredSize(GroupLayout.java:1325)
at javax.swing.GroupLayout.calculateAutopadding(GroupLayout.java:1050)
at javax.swing.GroupLayout.prepare(GroupLayout.java:1037)
at javax.swing.GroupLayout.preferredLayoutSize(GroupLayout.java:857)
at java.awt.Container.preferredSize(Container.java:1599)
at java.awt.Container.getPreferredSize(Container.java:1584)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1624)
at javax.swing.GroupLayout$ComponentSpring.calculateNonlinkedPreferredSize(GroupLayout.java:2944)
at javax.swing.GroupLayout$ComponentSpring.calculateNonlinkedMinimumSize(GroupLayout.java:2930)
at javax.swing.GroupLayout$ComponentSpring.calculateMinimumSize(GroupLayout.java:2897)
at javax.swing.GroupLayout$Spring.getMinimumSize(GroupLayout.java:1315)
at javax.swing.GroupLayout$ComponentSpring.calculatePreferredSize(GroupLayout.java:2904)
at javax.swing.GroupLayout$Spring.getPreferredSize(GroupLayout.java:1325)
at javax.swing.GroupLayout$Group.getSpringSize(GroupLayout.java:1604)
at javax.swing.GroupLayout$Group.calculateSize(GroupLayout.java:1593)
at javax.swing.GroupLayout$Group.calculatePreferredSize(GroupLayout.java:1568)
at javax.swing.GroupLayout$Spring.getPreferredSize(GroupLayout.java:1325)
at javax.swing.GroupLayout$Group.getSpringSize(GroupLayout.java:1604)
at javax.swing.GroupLayout$Group.calculateSize(GroupLayout.java:1588)
at javax.swing.GroupLayout$Group.calculatePreferredSize(GroupLayout.java:1568)
at javax.swing.GroupLayout$Spring.getPreferredSize(GroupLayout.java:1325)
at javax.swing.GroupLayout$Group.getSpringSize(GroupLayout.java:1604)
at javax.swing.GroupLayout$Group.calculateSize(GroupLayout.java:1588)
at javax.swing.GroupLayout$Group.calculatePreferredSize(GroupLayout.java:1568)
at javax.swing.GroupLayout$Spring.getPreferredSize(GroupLayout.java:1325)
at javax.swing.GroupLayout$SequentialGroup.setValidSize(GroupLayout.java:1972)
at javax.swing.GroupLayout$Group.setSize(GroupLayout.java:1553)
at javax.swing.GroupLayout.calculateAutopadding(GroupLayout.java:1058)
at javax.swing.GroupLayout.layoutContainer(GroupLayout.java:897)
at java.awt.Container.layout(Container.java:1421)
at java.awt.Container.doLayout(Container.java:1410)
at java.awt.Container.validateTree(Container.java:1507)
at java.awt.Container.validateTree(Container.java:1513)
at java.awt.Container.validateTree(Container.java:1513)
at java.awt.Container.validateTree(Container.java:1513)
at java.awt.Container.validateTree(Container.java:1513)
at java.awt.Container.validateTree(Container.java:1513)
at java.awt.Container.validate(Container.java:1480)
at java.awt.Window.dispatchEventImpl(Window.java:2473)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Je suppose que c'est un bug swing. Cela pourrait-il être un problème dans ma mise en œuvre? Pourquoi cela se passe-t-il 1 fois sur 10 et pas toujours? Puis-je faire quelque chose pour l'éviter?
vous ne commencez l'interface graphique de l'EDT? – willcodejavaforfood
@willcodejavaforfood: Bon point. Je suis d'avis que Swing devrait lancer des exceptions si les opérations de GUI sont effectuées en dehors du Thread Dispatch d'événement (comme SWT). En ne lançant pas d'exceptions, ils s'érigent en violation du principe du moindre étonnement. :) –
@Adam Paynter IMO Swing n'aurait pas dû être hostile au thread. Mais c'est le cas et il n'y a pas grand chose à faire à ce sujet maintenant. –