“Exception in thread ”AWT-EventQueue-0“ java.lang.NullPointerException”. I have no clue what I'm doing wrong

前端 未结 1 1749
伪装坚强ぢ
伪装坚强ぢ 2021-01-25 15:31

I am making a calculator for an AP Computer Science Final. I built the GUI in Eclipse using Jigloo, and I quickly tried to learn about Action Listeners so you can hit the button

相关标签:
1条回答
  • 2021-01-25 16:24

    You button variables aren't assigned until you call initGUI(), which is at the bottom of your constructor. So, when you do this:

    jButton3.addActionListener(new ListenToOne());
    

    ... Java sees this:

    null.addActionListener(new ListenToOne());
    

    ... which is obviously a problem.

    0 讨论(0)
提交回复
热议问题