2016-04-14 15 views
1

當打開jar文件時,我可以看到主/資源文件夾中的fxml列表,但它仍然給我「java.lang.NullPointerException:位置是必需的。」錯誤。IntelliJ to jar給「java.lang.NullPointerException:位置是必需的。」

package fxproject; 

import javafx.application.Application; 
import javafx.fxml.FXMLLoader; 
import javafx.scene.Parent; 
import javafx.scene.Scene; 
import javafx.stage.Stage; 

public class ApplicationSplashScreen extends Application 
    { 
     Stage window; 
     public static void main(String args[]) 
     { 
      launch(args); 
     } 

     @Override 
     public void start(Stage primaryStage) throws Exception 
     { 
      window = primaryStage; 
      loadDatabaseScreen(); 
      window.close(); 
     } 

     private void loadDatabaseScreen() 
     { 
      try 
      { 
       Stage stage = new Stage(); 
       Parent root = FXMLLoader.load(getClass().getResource("../main/resources/DatabaseSettingsForm.fxml")); 
       Scene scene = new Scene(root); 
       stage.setScene(scene); 
       stage.sizeToScene(); 
       stage.show(); 
      } 
      catch(Exception e) 
      { 
       new OrchidAlertBox("Error",e.toString()); 
      } 
     } 
    } 
+0

嘗試從字符串中刪除'../main/resources/'。 –

回答

0

我提出一個簡單的嘗試:查找當前目錄,然後粘貼(或使用絕對路徑)fxml到該目錄:

public static void main(String args[]) 
    { 
     //1. find current working dirrectory 
     System.out.println(new File(".").getAbsolutePath()); 
     //2. paste fxml's to this directory or modify ../main/.. to absolute path 
     //3. run program again? 
     launch(args); 
    } 
+1

謝謝,這幫助我找到了路徑。 – user6206262

0

您應該刪除的路徑,而不是隻使用/DatabaseSettingsForm.fxml

Stage stage = new Stage(); 
Parent root = FXMLLoader.load(getClass().getResource("/DatabaseSettingsForm.fxml")); 
+0

謝謝,剛試過這個,沒有任何改變。 – user6206262

相關問題