I'm trying to open an image in JavaFX and am getting this error
Caused by: java.io.FileNotFoundException: calibre/Books/1.png (No such file or directory)
at java.io.FileInputStream.open0(Native Method)
I think i'm getting my directories wrong somehow.
This is the method where I create the image.
public class Calibre extends Application {
@Override
public void start(Stage stage) throws Exception {
FileInputStream input = new FileInputStream("calibre/Books/1.png");
Image image = new Image(input);
ImageView imageView = new ImageView(image);
HBox hbox = new HBox(imageView);
Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
root.setId("pane");
Scene scene = new Scene(root);
stage.setScene(scene);
scene.getStylesheets().addAll(this.getClass().getResource("style.css").toExternalForm());
Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds();
//Set Stage Boundaries to visible bounds of the main screen
stage.setX(primaryScreenBounds.getMinX());
stage.setY(primaryScreenBounds.getMinY());
stage.setWidth(primaryScreenBounds.getWidth());
stage.setHeight(primaryScreenBounds.getHeight());
stage.show();
}
This is my directory, as you can see my images are stored inside.
Any help is greatly appreciated.