我想讓我的項目一個可運行的jar但問題是,gui沒有顯示出來。從我的cmd中的錯誤,我告訴它是關於我的圖像瀏覽。Java Runnable jar與ImageView不顯示GUI
我的項目包含位於除sourcefoler之外的另一個文件夾中的圖像視圖。我已經設置了構建路徑,但它似乎仍然沒有工作
這是我的圖像添加到GUI:
String path = "./imageTest/";
File folder = new File(path);
File[] listOfFiles = folder.listFiles();
for (File file : listOfFiles) { <----- Line 51
ImageView imageView;
imageView = createImageView(file);
tile.getChildren().addAll(imageView);
}
文件夾imageTest添加爲sourcefolder在構建路徑
這是通過CMD運行罐子時,我得到的錯誤:
"Exception in Application start method
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
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(Unknown Source)
Caused by: java.lang.NullPointerException
at application.guifx.MainScreen.mainScene(MainScreen.java:51)
at application.guifx.MainApp.start(MainApp.java:37)
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"
這是MainApp
public class MainApp extends Application {
private Service service;
private Stage stage;
private ScrollPane root = new ScrollPane();
private MainScreen mainScreen;
public MainApp() {
service = Service.getService();
StorageInitializer.initStorage();
}
@Override
public void start(Stage primaryStage) throws Exception {
service = Service.getService();
stage = primaryStage;
mainScreen = new MainScreen(stage);
stage.setWidth(100);
stage.setHeight(100);
primaryStage.setWidth(1000);
primaryStage.setHeight(850);
Scene scene = mainScreen.mainScene();<----- Line 37
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
要清楚...該程序通過月食laucnhing時工作,但沒有當我讓它運行的JAR 這是系統從日食 Link
的【什麼是一個NullPointerException,如何解決呢?(可能的複製http://stackoverflow.com/questions/218384/what-is-a- nullpointerexception-and-how-do-i-fix-it) – Seelenvirtuose