【发布时间】:2020-08-14 23:53:46
【问题描述】:
我正在尝试在 JavaFX 中打开图像并收到此错误
Caused by: java.io.FileNotFoundException: calibre/Books/1.png (No such file or directory)
at java.io.FileInputStream.open0(Native Method)
我想我的目录不知何故弄错了。
这是我创建图像的方法。
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();
}
这是我的目录,你可以看到我的图片存储在里面。
非常感谢任何帮助。
【问题讨论】:
标签: java image javafx netbeans imageview