打开jar文件时,我可以在main / resource文件夹中看到fxml的列表,但它仍然给我“java.lang.NullPointerException:Location is required”。错误。
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 :(得分:0)
您应该删除路径,而只需使用/DatabaseSettingsForm.fxml
Stage stage = new Stage();
Parent root = FXMLLoader.load(getClass().getResource("/DatabaseSettingsForm.fxml"));
答案 1 :(得分: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);
}