1 year ago

#382480

test-img

Martin Parunev

IllegalArgumentException not sure if I wrote the array right

    gamePanel gp;
    Tile[] tile;


    public tileManager(gamePanel gp){
        this.gp = gp;
        tile = new Tile[10]; // this means we're going to create 10 types of tiles (water, grass, water, sand, etc...)
        getTileImage();
    }

    public void getTileImage(){

        try{
            tile[0] = new Tile();
            tile[0].image = ImageIO.read(requireNonNull(getClass().getResourceAsStream("res/tiles/grass.png")));

            tile[1] = new Tile();
            tile[1].image = ImageIO.read(requireNonNull(getClass().getResourceAsStream("/tiles/wall.png")));

            tile[2] = new Tile();
            tile[2].image = ImageIO.read(requireNonNull(getClass().getResourceAsStream("/tiles/water.png")));

        } catch (IOException e) {
            e.printStackTrace();
        }


    }

    public void draw(Graphics2D g2){
        g2.drawImage(tile[0].image,0, 0, gp.tileSize, gp.tileSize, null);
    }
}

First picture Second Picture

So I'm trying to add tiles inside my game but I don't get why is the error? I found this online so any suggestions how to fix that will be appreciated!

java

arrays

exception

null

project

0 Answers

Your Answer

Accepted video resources