I have created two imageviews one from fxml and another from primaryController method
Running from IDE.........1
But when building with maven and running....2
The stacktrace says.....
java.io.FileNotFoundException: src\main\resources\org\openjfx\icons\icons8-boombox-48.png (The system cannot find the path specified)
at java.base/java.io.FileInputStream.open0(Native Method)
at java.base/java.io.FileInputStream.open(FileInputStream.java:212)
at java.base/java.io.FileInputStream.<init>(FileInputStream.java:154)
at java.base/java.io.FileInputStream.<init>(FileInputStream.java:109)
at org.openjfx@1.0-SNAPSHOT/org.openjfx.PrimaryController.initialize(PrimaryController.java:19)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2655)
at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:2517)
at org.openjfx@1.0-SNAPSHOT/org.openjfx.App.start(App.java:16)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:832)
It cannot find the file specified.
So,I extracted the zip file built by maven and checked that there is not a single image present.So my question is that if there are no images in the zip file then how is the image loaded in case of fxml and not loaded from primaryController method.
Both images are shown from the same file.
package org.openjfx;
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
try {
Image image = new Image(new FileInputStream("src/main/resources/org/openjfx/icons/icons8-boombox-48.png"));
ImageView imageView = new ImageView(image);
imageView.setFitWidth(100);
imageView.setFitHeight(100);
anchorPane.getChildren().add(imageView);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}