hi all,
I'm getting the following due to the setText call in the change event handler. I must be missing something obvious but I don't see it right now!
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javaapplication4.Main.stateChanged(Main.java:49)
at javax.swing.AbstractButton.fireStateChanged(Abstra ctButton.java:1889)
at javax.swing.AbstractButton$Handler.stateChanged(Ab stractButton.java:2310)
at javax.swing.DefaultButtonModel.fireStateChanged(De faultButtonModel.java:333)
at javax.swing.DefaultButtonModel.setMnemonic(Default ButtonModel.java:274)
at javax.swing.AbstractButton.setMnemonic(AbstractBut ton.java:1548)
at javax.swing.AbstractButton.setMnemonic(AbstractBut ton.java:1569)
at javaapplication4.Main.<init>(Main.java:29)
at javaapplication4.Main$1.run(Main.java:42)
at java.awt.event.InvocationEvent.dispatch(Invocation Event.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java: 597)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:122)
public class Main implements ChangeListener { JButton jbtnFirst; JLabel jlab; Main() { JFrame jfrm = new JFrame("Testing Buttons!"); jfrm.setLayout(new FlowLayout()); jfrm.setSize(350, 350); jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jbtnFirst = new JButton("First"); jbtnFirst.addChangeListener(this); jbtnFirst.setMnemonic('F'); jfrm.add(jbtnFirst); jlab = new JLabel(); jfrm.add(jlab); jfrm.setVisible(true); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { new Main(); } }); } public void stateChanged(ChangeEvent ce) { jlab.setText("aa"); //What is wrong with this? } }