So, I have made a class called TileDrawer.java, which is supposed to load in a BufferedImage with the following code:
BufferedImage spriteSheet = null;    
public void initSpriteSheet() {
        try {
                this.spriteSheet = ImageIO.read(new File("resources\\spritesheet.png"));
        } catch (IOException e) {
                e.printStackTrace();
        }
}   
but when I try to run the method after initializing the object, it gives me this error:
javax.imageio.IIOException: Can't read input file!
This is my current full code for the TileDrawer class:
package mainGame;
        
//imports
                
public class TileDrawer {
        BufferedImage spriteSheet = null;    
                
         
        public void initSpriteSheet() {
                try {
                        this.spriteSheet = ImageIO.read(new File("resources\\spritesheet.png"));
                } catch (IOException e) {
                        e.printStackTrace();
                }
        }        
        
        //irrelevant methods were here
}
and I also have this class, called GamePanel with the following code:
package mainGame;
//imports
public class GamePanel extends JPanel implements Runnable {
        
        Thread gameThread;
        
        TileDrawer tileDrawer = new TileDrawer();
        //vars
        
        public GamePanel() {} //game panel
        
        public void startGameThread() {
                tileDrawer.initSpriteSheet(); //  <---  here                                                     
                gameThread = new Thread(this);
                gameThread.start();
        }
                 
        @Override
        public void run() {
                //stuff to make a functioning loop
                while (gameThread != null) {
                        
                        //more loop stuff
                        if (delta >= 1) { //delta is only used to cap the framerate
                                update();
                                repaint();
                                
                                //even more loop stuff
                        }
                }
        }
        public void update() {
                //update stuff here
        }
        protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                Graphics2D g2 = (Graphics2D)g;
                //drawing stuff goes here
                g2.dispose();
        }
}
Some background info:
- I am using Debian Linux
- The directory looks like this:
MyGame
|------build
|      |------(Compiled java files)
|------src
|      |------Main.java (irrelevant)
|      |------GamePanel.java
|      |------TileDrawer.java
|      |------resources
|      |      |------spriteSheet.png
- I am not using an IDE to compile my code, I am simply using these commands:
cd /home/{my username}/MyGame/
javac -d ./build src/Main.java src/GamePanel.java src/TileDrawer.java
cd build
java mainGame.Main
All of these things I tried, but none of them worked when I tried to implement them:
- changing the file path into singular normal slashes
- changing the file path into singular normal slashes and putting one at the front
- using a normal Image file instead of a BufferedImage
- putting the image file into the same directory as the java file
Any help on how to fix my problem would be greatly appreciated.
