所以,在将我的LWJGL编译为带有JarSplice的可运行Jar后,CMD告诉我的是什么。
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)
我追溯了问题,它与使用java.io.File
而不是InputStream()
有关,但问题是,我使用的是InputStream()
。
这是来自我的Image类。
public void init() {
try{
texture = TextureLoader.getTexture(textForm, new FileInputStream(textName), true);
}catch(IOException e){
System.out.println("Error: "+e);
}
rotation = 0;
if(width != height&&width % 2 != 0&&height % 2 != 0){
textForm = "PNG";
textName = "res/128.png";
JOptionPane.showMessageDialog(null, "The width and height of the Image should be equal.", "Wrong image size!", JOptionPane.WARNING_MESSAGE);
init();
}
timer = new Timer();
}
public void draw() {
if(ExtraBind){
glBindTexture(GL_TEXTURE_2D, texture.getTextureID());
}else{
texture.bind();
}
glColor4f(c4f[0], c4f[1], c4f[2], c4f[3]);;
glPushMatrix();
glTranslatef(x + width /2, y + height /2, 0);
glRotatef(rotation, 0, 0, 1f);
glTranslatef(-x - width /2, -y - height /2, 0);
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex2f(x, y);
glTexCoord2f(1,0);
glVertex2f(x + width,y);
glTexCoord2f(1,1);
glVertex2f(x + width, y + height);
glTexCoord2f(0,1);
glVertex2f(x, y + height);
glEnd();
glPopMatrix();
glBindTexture(GL_TEXTURE_2D, 0);
}
这是我想要从我的菜单类
加载的图像 IMG = new Image("PNG", "res/350.png", 0,0);
谢谢你的时间。
答案 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;
}