Cant find image file - java

35 views Asked by At

I get this when trying to compile runnable jar file:

Running...
Thread started
CRASH!
Exception in thread "Thread-0" java.lang.ExceptionInInitializerError
        at com.mime.project13d.graphics.Render3D.floor(Render3D.java:42)
        at com.mime.project13d.graphics.Screen.render(Screen.java:18)
        at com.mime.project13d.Display.render(Display.java:131)
        at com.mime.project13d.Display.run(Display.java:96)
        at java.base/java.lang.Thread.run(Thread.java:1623)
Caused by: java.lang.RuntimeException: java.io.FileNotFoundException: res\skytexture.png (Det går inte att hitta filen)
        at com.mime.project13d.graphics.Texture.loadBitmap(Texture.java:23)
        at com.mime.project13d.graphics.Texture.<clinit>(Texture.java:26)
        ... 5 more
Caused by: java.io.FileNotFoundException: res\skytexture.png (Det går inte att hitta filen)
        at java.base/java.io.FileInputStream.open0(Native Method)
        at java.base/java.io.FileInputStream.open(FileInputStream.java:219)
        at java.base/java.io.FileInputStream.<init>(FileInputStream.java:158)
        at java.base/java.io.FileInputStream.<init>(FileInputStream.java:112)
        at com.mime.project13d.graphics.Texture.loadBitmap(Texture.java:9)
        ... 6 more

The code for for the texture class is:

package com.mime.project13d.graphics;
import java.awt.image.BufferedImage;
import java.io.FileInputStream;

import javax.imageio.ImageIO;
public class Texture {
    public static Render loadBitmap(String fileName) {
        try {
            BufferedImage image = ImageIO.read(new FileInputStream(fileName));
            int width = image.getWidth();
            int height = image.getHeight();
            Render result = new Render(width,height);
            image.getRGB(0,0,width,height, result.pixels, 0, width);
            return result;
            
        } catch (Exception e) {
            System.out.println("CRASH!");
            throw new RuntimeException(e);
        }
    }
    public static Render ceiling = loadBitmap("res\\skytexture.png");
    public static Render floor = loadBitmap("res\\grassblock.png");
}

I was trying to load a 3d graphics texture (both dont work) by using the loadbitmap method. it did not work and pointed to this line: BufferedImage image = ImageIO.read(new FileInputStream(fileName));.

it worked in eclipse ide but a exported runnable does not work. i have refrenced the res files and tried writing "res\grassblock.png", "grassblock.png", "res/grassblock.png", "/res/grassblock.png"

Does someone know what is wrong with my code?

0

There are 0 answers