I'm trying to add an image in a JavaFX application, but for some reason it's not detecting the file or not recognizing the path. The error specifically is
IllegalArgumentException: Invalid URL or resource not found'...
Here is the relevant code:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
public class DisplayThreeCards extends Application {
@Override
public void start(Stage primaryStage) {
Pane pane = new HBox();
Image card1 = new Image("image/card/1.png");
pane.getChildren().add(new ImageView(card1));
Scene scene = new Scene(pane);
primaryStage.setTitle("Display Three Cards");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
Application.launch();
}
}
The image folder is located in my src folder, alongside my java file. Inside of the image folder is the card folder, so the location is correct.