Witam!
Problem następujący: po zapakowaniu w Runnable Jar
nie widzi obrazów. Natomiast kiedy w programie próbuję użyć this.getClass().getResourceAsStream()
to mi rzuca wyjątkiem Exception in Application start method java.lang.reflect.InvocationTargetException
Struktura programu:
Kod wygląda następująco:
void loadGraphics() {
Image image = new Image(this.getClass().getResourceAsStream("file:/images/back.png")); //Ten sposób nie działa
backIco = new ImageView();
backIco.setImage(image);
backIco.setFitHeight(28);
backIco.setFitWidth(28);
upIco = new ImageView(new Image(new File("images/up.png").toURI().toString())); //Tu jest wszystko ok do czasu exportu
upIco.setFitHeight(28);
upIco.setFitWidth(28);
newFileIco = new ImageView(new Image(new File("images/add.png").toURI().toString()));
newFileIco.setFitHeight(28);
newFileIco.setFitWidth(28);
newDirIco = new ImageView(new Image(new File("images/folder.png").toURI().toString()));
newDirIco.setFitHeight(28);
newDirIco.setFitWidth(28);
deleteIco = new ImageView(new Image(new File("images/error.png").toURI().toString()));
deleteIco.setFitHeight(28);
deleteIco.setFitWidth(28);
}
Próbowałem praktycznie wszystkiego:
Image image = new Image(this.getClass().getResourceAsStream("file:/images/back.png"));
Image image = new Image(this.getClass().getResourceAsStream("file:images/back.png"));
Image image = new Image(this.getClass().getResourceAsStream("/images/back.png"));
Image image = new Image(this.getClass().getResourceAsStream("images/back.png"));
Importy są ok.
ImageIO
potrzebuje obiektu typu BufferedImage
a mi potrzebny jest ImageView
, więc też nie wchodzi w grę.
Jak to zrobić, aby zarówno w Runnable Jar
jak i IDE wszystko śmigało?
Pomocy, bo mózg mi od tego paruje, czuję się jak debil (i słusznie!)...
EDIT
Jeszcze stacktrace
:
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException: Input stream must not be null
at javafx.scene.image.Image.validateInputStream(Image.java:1128)
at javafx.scene.image.Image.<init>(Image.java:706)
at files.explorer.GUI.loadGraphics(GUI.java:33)
at files.explorer.GUI.start(GUI.java:156)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
... 1 more
Exception running application files.explorer.GUI
Linki, które przeczytałem, lecz nie znalazłem rozwiązania: