我的应用程序(Java)有什么问题?
我正在尝试制作一个游戏,我正在使用一个我找到的瓷砖集(png)。我希望能够将图像分解为多个部分,并将它们放置在jframe中的特定位置以显示运动。但首先,我如何开始导入图像。我所有的尝试都失败了,导入时图像会变成文本文件。请帮助解决这个问题,我将如何切割和安排瓷砖我的应用程序(Java)有什么问题?,java,image,swing,import,tiles,Java,Image,Swing,Import,Tiles,我正在尝试制作一个游戏,我正在使用一个我找到的瓷砖集(png)。我希望能够将图像分解为多个部分,并将它们放置在jframe中的特定位置以显示运动。但首先,我如何开始导入图像。我所有的尝试都失败了,导入时图像会变成文本文件。请帮助解决这个问题,我将如何切割和安排瓷砖 我确信字符串的正确格式应该从/ 我在当地查过了。请看这张照片 删除路径中png后的斜杠(“assets/tilesetbackground.png”),我试过了,但没有成功。我还尝试了(“assets/tilesetbackgrou
我确信字符串的正确格式应该从/ 我在当地查过了。请看这张照片
删除路径中png后的斜杠(“assets/tilesetbackground.png”),我试过了,但没有成功。我还尝试了(“assets/tilesetbackground.png”)、(“/assets/tilesetbackground.png/”、(“/assets/tilesetbackground.png”)、(((/assets/tilesetbackground.png/”)和(“f://assets/tilesetbackground.png/”)项目中的图像位于哪里?发布源目录的树。如果路径不是以
/
开头,Class.getResource()将开始查找类的包。
Exception in thread "main" java.lang.IllegalArgumentException: input == null!
at javax.imageio.ImageIO.read(Unknown Source)
at World.Display.<init>(Display.java:15)
at Main
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
World.Display l = new World.Display();
}
}
package World;
import java.awt.GridLayout;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Display {
public Display() throws IOException{
BufferedImage img=ImageIO.read(getClass().getResource("assets/tilesetbackground.png/"));
ImageIcon icon=new ImageIcon(img);
JFrame frame=new JFrame();
frame.setTitle("Another RPG Version: "+Config.Global.Version);
frame.setLayout(new GridLayout(1024,768));
frame.setSize(1024,768);
JLabel lbl=new JLabel();
lbl.setIcon(icon);
frame.add(lbl);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}