所以我正在尝试测试我的TileC
类,但每当我运行它时,它会显示运行时错误java.lang.IllegalArgumentException: input == null!
。我不确定为什么,因为我的路径String Path = "/CourseworkAY/res/NormalSwamp.gif";
似乎是正确的?
以下是TileC类中的所有代码:
import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class TileC extends JPanel {
BufferedImage tileImage;
static JFrame test = new JFrame("Test");
static JPanel userDetailsPanel = new JPanel();
public TileC(BufferedImage img) {
tileImage = img;
}
protected void paintComponent(Graphics g) {
int width = getWidth();
int height = getHeight();
for (int x = 0; x < width; x += tileImage.getWidth()) {
for (int y = 0; y < height; y += tileImage.getHeight()) {
g.drawImage(tileImage, x, y, this);
}
}
}
public static void main(String[] args) throws IOException {
test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String Path = "/CourseworkAY/res/NormalSwamp.gif";
BufferedImage image = ImageIO.read(TileC.class.getResource(Path));
TileC backgroundImage = new TileC(image);
test.setContentPane(backgroundImage);
test.setLayout(new BorderLayout());
userDetailsPanel.setOpaque(false);
test.add(userDetailsPanel, BorderLayout.CENTER);
test.setSize(400,400);
test.setVisible(true);
}
}
我已经检查了很多其他相关的问题,但没有一个答案对我有帮助,有人可以解决一些问题吗?