1

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.

ItachiUchiha
  • 36,135
  • 10
  • 122
  • 176
  • What is the location of the image? – ItachiUchiha Apr 07 '15 at 06:37
  • [Here's a picture.](http://puu.sh/h0mVY/4641f60a13.png) DisplayThreeCards is in src, the pictures I want are located in image/card, and image is located in the src folder with my java file. –  Apr 07 '15 at 06:40
  • The path and the code are perfect. Are you using an IDE for execution? – ItachiUchiha Apr 07 '15 at 06:46
  • Be sure that the image files has an extension png. – Uluk Biy Apr 07 '15 at 06:52
  • 1
    You must have a **package** with name `image.card` inside `src` and image must be stored in it. The reason is unless they are included in build-path, the contents will not be copied into the bin directory. – ItachiUchiha Apr 07 '15 at 06:59
  • Thanks for that, I appreciate it. Things are working now! –  Apr 07 '15 at 07:08
  • That's very awesome and all, but could you please not waste everyone's time reading this and use the answer for that instead of using comments for answering? Or just change the title to "SOLVED: ..." – Roland Apr 07 '15 at 09:01
  • Possible duplicate of [java.lang.IllegalArgumentException: Invalid URL or resource not found](https://stackoverflow.com/questions/16990482/java-lang-illegalargumentexception-invalid-url-or-resource-not-found) – Rachel Gallen Jun 05 '17 at 18:51

0 Answers0