我正在尝试向我的程序中添加一个工具栏,但是当我添加代码时,我得到了一个空指针异常,有人知道为什么会发生这种情况吗?
public JButton makeButton(String imageName,
String toolTipText) {
//Look for the image.
String imgLocation = "images/" + imageName + ".jpg";
URL imageURL = assignment3.class.getResource(imgLocation);
//Create and initialize the button.
JButton button = new JButton();
button.setToolTipText(toolTipText);
button.addActionListener(this);
button.setIcon(new ImageIcon(imageURL));
return button;
}
例外是
Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at assignment3.assignment3.makeButton(assignment3.java:331)