我正在尝试在JPanel上显示图片,但我不断收到错误消息:
java.lang.IllegalArgumentException:输入== null!
我不明白发生了什么。
这是我正在使用的代码:
public void actionPerformed(ActionEvent e) {
try {
Image image=ImageIO.read(getClass().getResource("img/" +num.getText()+".jpg"));
Image resized = image.getScaledInstance(200, 200, 100);
pictureFrame.setIcon(new ImageIcon(resized));
} catch (Exception ex){
ex.printStackTrace();
}
}
这只是导致我得到错误!
堆栈跟踪产生以下内容:
Java.lang.IllegalArgumentException: input == null!
at javax.imageio.ImageIO.read(ImageIO.java:1362)
at work.Item.actionPerformed(Item.java:96)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6297)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3275)
at java.awt.Component.processEvent(Component.java:6062)
at java.awt.Container.processEvent(Container.java:2039)
at java.awt.Component.dispatchEventImpl(Component.java:4660)
at java.awt.Container.dispatchEventImpl(Container.java:2097)
at java.awt.Component.dispatchEvent(Component.java:4488)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4575)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4236)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4166)
at java.awt.Container.dispatchEventImpl(Container.java:2083)
我该如何解决?我检查了图像的位置,并尝试从不同的位置进行操作,总是得到相同的错误!
我正在使用Netbeans IDE。
莫回无
相关分类