所有新的JavaFXML项目均无法运行,在应用程序启动方法java.lang.reflect.InvocationTargetException中返回Exception

时间:2018-12-05 10:35:37

标签: javafx

所有javafxml项目均无法运行。甚至新的未编辑的。我已经下载了一些教授的fxml项目,并且它们全部运行都没有问题。我还能够运行一些旧项目。 为了简单起见,我将包括一个全新的项目,而不是我的错误缠身的任务。

笔记本电脑和台式机上问题仍然存在。 Ive在课堂上也四处询问,没有其他人遇到过类似的问题。我也搜索并尝试了不同的解决方案,甚至尝试了Google搜索的第2页。

任何帮助将不胜感激。

主要:

package fxmltest;

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


public class FXMLtest extends Application {

@Override
public void start(Stage stage) throws Exception {
    Parent root = 
FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));

    Scene scene = new Scene(root);

    stage.setScene(scene);
    stage.show();
}

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    launch(args);
}

}

控制器:

 package fxmltest;

 import java.net.URL;
 import java.util.ResourceBundle;
 import javafx.event.ActionEvent;
 import javafx.fxml.FXML;
 import javafx.fxml.Initializable;
 import javafx.scene.control.Label;

 public class FXMLDocumentController implements Initializable {

@FXML
private Label label;

@FXML
private void handleButtonAction(ActionEvent event) {
    System.out.println("You clicked me!");
    label.setText("Hello World!");
}

@Override
public void initialize(URL url, ResourceBundle rb) {
    // TODO
}    

}

FXML:

<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?> 
<?import java.util.*?> 
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" 
xmlns:fx="http://javafx.com/fxml/1" 
fx:controller="fxmltest.FXMLDocumentController">
<children>
    <Button layoutX="126" layoutY="90" text="Click Me!" 
 onAction="#handleButtonAction" fx:id="button" />
    <Label layoutX="126" layoutY="120" minHeight="16" minWidth="69" 
 fx:id="label" />
</children>
</AnchorPane>

堆栈跟踪:

    ant -f C:\\Users\\Oskar\\Documents\\NetBeansProjects\\FXMLtest -Djavac.includes=fxmltest/FXMLtest.java -Dnb.internal.action.name=run.single -Drun.class=fxmltest.FXMLtest run-single
init:
deps-jar:
Created dir: C:\Users\Oskar\Documents\NetBeansProjects\FXMLtest\build
Updating property file: C:\Users\Oskar\Documents\NetBeansProjects\FXMLtest\build\built-jar.properties
Created dir: C:\Users\Oskar\Documents\NetBeansProjects\FXMLtest\build\classes
Created dir: C:\Users\Oskar\Documents\NetBeansProjects\FXMLtest\build\empty
Created dir: C:\Users\Oskar\Documents\NetBeansProjects\FXMLtest\build\generated-sources\ap-source-output
Compiling 1 source file to C:\Users\Oskar\Documents\NetBeansProjects\FXMLtest\build\classes
compile-single:
run-single:
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:498)
    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:498)
    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$154(LauncherImpl.java:182)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException: Location is required.
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3207)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
    at fxmltest.FXMLtest.start(FXMLtest.java:22)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(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$147(WinApplication.java:177)
    ... 1 more
    Exception running application fxmltest.FXMLtest
    C:\Users\Oskar\Documents\NetBeansProjects\FXMLtest\nbproject\build- 
    impl.xml:1052: The following error occurred while executing this line:
    C:\Users\Oskar\Documents\NetBeansProjects\FXMLtest\nbproject\build- 
    impl.xml:806: 
    Java returned: 1
    BUILD FAILED (total time: 1 second)

0 个答案:

没有答案
相关问题