2013-09-09 3 views
0

Итак, вот что говорит CMD после компиляции моего LWJGL для запуска Jar с JarSplice.Файл не найден после создания runnable jar с использованием jarsplice

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().

Это из моего класса изображения.

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

Относительный вопрос пути! – devnull

+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(); 
    } 

И я добавил этот метод для загрузки из файла банки.

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; 
} 
Смежные вопросы