0

What will be the picture.jpg absolute image path and relative image path for the following directory structure?

Directory structure

JavaProject  
    |_Package1  
    |    |_App1.java
    |
    |_Package2
         |
       PICS
         |_picture.jpg

Code

public class App1 extends Application{
    ...
    Image picturePath = new Image( ??? );
    ImageView picture = new ImageView(picturePath);
    ...
}
ItachiUchiha
  • 36,135
  • 10
  • 122
  • 176
Toebi
  • 5
  • 5
  • possible duplicate of [Cannot load image in JavaFX](http://stackoverflow.com/questions/16099427/cannot-load-image-in-javafx) – Buddy Jul 23 '15 at 02:59
  • My bad! I made the directory structure wrong. The Pics directory should be in another Java Project directory. I know how to create image path if the PICS directory locates under the same project directory. But I don't know how to create a path for the PICS directory locates at different project directory. – Toebi Jul 23 '15 at 20:38

1 Answers1

1

The absolute path, relative to your project is :

Image picturePath = new Image("/Package2/Picture/picture.jpg");

If you need a path relative to the class file, you may use :

Image picturePath = new Image("../Package2/Picture/picture.jpg");
ItachiUchiha
  • 36,135
  • 10
  • 122
  • 176