#Debugging issues

1 messages · Page 1 of 1 (latest)

late minnow
#

Hello ! I'm new at programming in java and i need help for a school project. I need to make the bases of a game, and i wanted to recreate the legend of zelda a link to the past. I have some issues with the way I'm managing my tiles, but I don't know how to fix this. Here is my file :

jade lagoonBOT
#

<@&987246487241105418> please have a look, thanks.

late minnow
jade lagoonBOT
late minnow
#

and here is the console :

supple citrus
#

the problem is in TileManager line 30

#

what is in that line

late minnow
#

BufferedReader br = new BufferedReader(new InputStreamReader(is));

supple citrus
#

ah well the problem is the way you try to load the file

#

it is in the resources folder right?

late minnow
#

yess, his path is /res/maps/maptestdata.txt

supple citrus
#

get the input stream from resources using getClass().getResourceAsStream(...)

late minnow
#

like this ?

InputStream is = getClass().getResourceAsStream("file:/res/maps/maptestdata.txt");

supple citrus
#

yeah

#

well

#

remove the file:

#

you dont need that

#

also you should take a look at try with resource

late minnow
late minnow
late minnow
#

oh a try catch structure ?

#

or is it different

supple citrus
#

is it basically what you have, but with a try(...)

#

read the article

#

it explans in detail

late minnow
#

yeah reading it, thanks !

supple citrus
#

especially related to your inputstream and bufferreader as they are AutoCloseable

late minnow
#

so like this if I understood well ?

public TileManager(GamePanel gPanel) {
    this.gPanel = gPanel;
    this.tileSize = GamePanel.getTileSize(); // Obtient la taille des tuiles depuis GamePanel
    
    try (InputStream is = getClass().getResourceAsStream("/res/maps/maptestdata.txt");
         BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
        
        String line;
        while ((line = br.readLine()) != null) {
            fileNames.add(line);
            collisionStatus.add(br.readLine());
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    
    tiles = new Tile[fileNames.size()];
    loadTileImages();
    
    mapTileNum = new int[gPanel.WORLD_WIDTH][gPanel.WORLD_HEIGHT];
    loadTileImages();
    loadMap("file:res/maps/maptest.txt"); // Assurez-vous que loadMap est appelé ici pour remplir mapTileNum
}
late minnow
#

so it did'nt worked for me

jade lagoonBOT
#
TJ-Bot
Get help

: If you are in need of help with Java programming, the "Java Q&A" category on our Discord server is the perfect place for you. Whether you are struggling with a specific coding problem, looking for guidance on best practices, or seeking recommendations for resources, our community of experienced Java developers is here to assist you.

To get help in the Java Q&A category, simply post your question or issue in the chat and wait for a response from fellow members. Be sure to provide as much detail as possible to help others understand the problem and offer accurate solutions. Additionally, remember to follow the server rules and guidelines to maintain a respectful and productive environment for all participants.

Our Java Q&A category is a valuable resource for anyone looking to improve their programming skills or overcome challenges in their projects. By engaging with our community of experts and enthusiasts, you can gain valuable insights, learn new techniques, and ultimately enhance your proficiency in Java development.

Don't hesitate to reach out for assistance in the Java Q&A category – we are here to support you on your journey to becoming a proficient Java programmer.