I\'m working through a book, and the following code throws a NPE at runtime when the JButton is clicked, at the line button.actionPerformed. I\'ve done my best to be sure m
The reason is this Line:
JButton button = new JButton("click here");
Here you are creating new local JButton object which is shadowing the member variable button . Hence button is still null. You should instead use:
JButton
button
null
button = new JButton("click here");