0

I want to load an image to a javafx programme using only the path "logo.jpg". However, it does not work. The fullpath can also work clearly. My instructor can work the program using the path "logo.jpg" on his/her computer. Both of us use eclipse. What is the reason of this issue?

My project like that;

-ProgDemo

-src

  -application

    -ImageDemo.java
    -application.css
    -logo.jpg 

My Codes;

Image image = new Image("C:\\Users\\xxx\\eclipse-workspace\\ProgDemo\\src\\application\\logo.jpg");
    ImageView imgView = new ImageView(image); 
    
    BorderPane pane = new BorderPane();
    
    pane.setCenter(imgView);
    
    Scene scene = new Scene(pane,1000,1000);
    primaryStage.setTitle("Finally we win.");
    primaryStage.setScene(scene);
    primaryStage.show();
  • 3
    Read the documentation (particularly the examples there). The constructor is expecting a URL, not a file path. – James_D Apr 19 '23 at 09:48

0 Answers0