Java 使用jarsplice创建可运行jar后找不到文件
下面是CMD在用JarSplice将LWJGL编译成可运行Jar后告诉我的Java 使用jarsplice创建可运行jar后找不到文件,java,jar,textures,inputstream,lwjgl,Java,Jar,Textures,Inputstream,Lwjgl,下面是CMD在用JarSplice将LWJGL编译成可运行Jar后告诉我的 C:\Users\Rose>java -jar C:\Users\Rose\Desktop\Test\FrikFatJar.jar Error: java.io.FileNotFoundException: res\350.png (The system cannot find the pa th specified) loading glyphs -1 glyphs loaded loading glyphs -
C:\Users\Rose>java -jar C:\Users\Rose\Desktop\Test\FrikFatJar.jar
Error: java.io.FileNotFoundException: res\350.png (The system cannot find the pa
th specified)
loading glyphs -1
glyphs loaded
loading glyphs -1
glyphs loaded
Exception in thread "main" java.lang.NullPointerException
at frik.entity.Image.draw(Image.java:164)
at frik.screen.Menu.draw(Menu.java:44)
at frik.main.FrikMolder.updateContent(FrikMolder.java:77)
at frik.main.FrikMolder.isRunning(FrikMolder.java:54)
at frik.main.MainClass.<init>(MainClass.java:36)
at frik.main.MainClass.main(MainClass.java:74)
这就是我试图从菜单类加载的图像
IMG=新图像(“PNG”,“res/350.PNG”,0,0)代码>
感谢您抽出时间。我已经修复了它,这是我在init()中更改的内容。
public void init() {
try{
if(Special == true){
texture = TextureLoader.getTexture(textForm, loadBufferedImage(textName), true);
}else{
texture = TextureLoader.getTexture(textForm, new FileInputStream(textName), true);
}
}catch(IOException e){
System.out.println("Error: "+e);
}
Special = true;
rotation = 0;
if(width != height&&width % 2 != 0&&height % 2 != 0){
textForm = "PNG";
textName = "/img/128.png";
Special = false;
JOptionPane.showMessageDialog(null, "The width and height of the Image should be equal.", "Wrong image size!", JOptionPane.WARNING_MESSAGE);
init();
}
我添加了这个从jar文件加载的方法
private InputStream loadBufferedImage(String string)
{
try
{
BufferedImage bi = ImageIO.read(this.getClass().getResource(string));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write( bi, "PNG", baos);
InputStream is = new ByteArrayInputStream(baos.toByteArray());
return is;
} catch (IOException e)
{
System.out.println("Error: "+e);
}
return null;
}
你能再解释一下吗?
private InputStream loadBufferedImage(String string)
{
try
{
BufferedImage bi = ImageIO.read(this.getClass().getResource(string));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write( bi, "PNG", baos);
InputStream is = new ByteArrayInputStream(baos.toByteArray());
return is;
} catch (IOException e)
{
System.out.println("Error: "+e);
}
return null;
}