File not found issue JAVAFX

31 Views Asked by At

I have an issue with getResource() method

public void initialize(URL url, ResourceBundle resourceBundle) {
        recommendations = new ArrayList<>(getRecommendations());
        for (int i = 0; i < recommendations.size(); i++) {
            try {
                FXMLLoader loader = new FXMLLoader(getClass().getResource("song.fxml"));
                VBox songLayout = loader.load();

                // Access the controller and set data for the song card
                SongController songController = loader.getController();
                songController.setData(recommendations.get(i));

                int row = i / 3; // Calculate row index
                int column = i % 3; // Calculate column index

                songsGrid.add(songLayout, column, row);
            } catch (IOException e) {
                e.printStackTrace();
            } catch (NullPointerException ex) {
                ex.printStackTrace();
                // Ensure that song.fxml or songsGrid is not null
            } catch (Exception exc) {
                exc.printStackTrace();
                // Catch any other potential exceptions
            }
        }
    }

And this is my project structure

hkj

The error given is that the Location is not set. Is there any solution for that ?

0

There are 0 best solutions below