我的问题是我的javafx应用程序jar,由Eclipse mars生成。实际上,如果我在eclipse中运行,一切都运行良好。但是,当我使用命令行并尝试运行以前由eclipse创建的应用程序的jar时,使用以下命令:
java -jar TalanTestingWithXPathFX.jar
我的终端出了很多错误。错误如下:
Exception in Application start method
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 com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source)
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 sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalStateException: Location is not set.
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at talan.test.webApp.MainApp.initRootLayout(Unknown Source)
at talan.test.webApp.MainApp.start(Unknown Source)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162 (Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(Unknown Source)
... 1 more
Exception running application talan.test.webApp.MainApp
答案 0 :(得分:0)
这是主类的一些代码
public class MainApp extends Application {
@FXML
private static Stage primaryStage;
@FXML
private AnchorPane rootLayout;
public Project mainProject;
public static rootLayOutController rootController;
@Override
public void start(Stage primaryStage) {
this.primaryStage = primaryStage;
this.primaryStage.setResizable(true);
this.primaryStage.setTitle("AutoGenDriver");
initRootLayout();
//showSubWindow();
}
/**
* Initializes the root layout.
*/
public void initRootLayout() {
try {
// Load root layout from fxml file.
FXMLLoader loader = new FXMLLoader();
loader.setLocation(MainApp.class.getResource("./view/rootLayOut.fxml"));
rootLayout = loader.load();
// Show the scene containing the root layout.
Scene scene = new Scene(rootLayout);
//
primaryStage.setScene(scene);
rootController=loader.getController();
// Give the controller access to the main app.
rootLayOutController controller = loader.getController();
controller.setMainApp(this);
primaryStage.show();
} catch (IOException e) {
System.out.println("Loading error");
}
}
public void setProject(Project p){
this.mainProject = p;
}
/**
* Called when the user clicks New Project.
*/
@FXML
public static Project showNewProjectDialog() {
try {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(MainApp.class.getResource("view/newProjectDialog.fxml"));
AnchorPane page = loader.load();
// Create the dialog Stage.
Stage dialogStage = new Stage();
dialogStage.setTitle("Add new Test Project");
dialogStage.initModality(Modality.WINDOW_MODAL);
dialogStage.initOwner(primaryStage);
Scene scene = new Scene(page);
dialogStage.setScene(scene);
// Set the project into the controller.
newProjectDialogController controller = loader.getController();
controller.setDialogStage(dialogStage);
// controller.setProject(project);
// Show the dialog and wait until the user closes it
dialogStage.showAndWait();
return controller.getProject();
} catch (IOException e) {
System.out.println("Loading error");
return null;
}
}
public static void setPrimaryStage(Stage primaryStage) {
MainApp.primaryStage = primaryStage;
}
/**
* Returns the main stage.
* @return
*/
public static Stage getPrimaryStage() {
return primaryStage;
}
public static void main(String[] args) {
launch(args);
}
这是来自rootLayOutController类的一些代码
public void setRootTreeView(String nameProject) {
Image image=new Image(new File("C:\\Users\\DELL 3521\\workspaceMars\\TalanTestingFX\\Images\\dossier.png").toURI().toString(),20,20,true,true);
ImageView imv= new ImageView();
imv.setImage(image);
TreeItem<String> rootNode = new TreeItem<String>(tempProject.getName(),imv);
rootNode.setExpanded(true);
testProject.add(rootNode);
t.setRoot(rootNode);
}
/**
* add sub Elements to the TreeView
*
* @param mainApp
*/
public void addItemToTreeView(String item) {
testProject.get(0).getChildren().add(new TreeItem<String>(item));
}
public static Template getTemplate() {
return template;
}
public static void setTemplate(Template template) {
rootLayOutController.template = template;
}
public AnchorPane getContent() {
return content;
}
public void setContent(AnchorPane content) {
this.content = content;
}
/**
* Initializes the controller class. This method is automatically called
* after the fxml file has been loaded.
*/
@FXML
private void initialize() {
handleTreeViewSelectElement();
newSuiteItem.setDisable(true);
openPageItem.setDisable(true);
cnxItem.setDisable(true);
openPageItem.setDisable(true);
scItem.setDisable(true);
acItem.setDisable(true);
dactItem.setDisable(true);
}