Netbeans-应用程序启动方法java.lang.reflect.InvocationTargetException中的异常

时间:2018-11-23 21:12:45

标签: java netbeans-8

这是我的控制者:

package projectaddflight;

import java.io.FileNotFoundException;
import java.net.URL;
import java.util.Formatter;
import java.util.FormatterClosedException;
import java.util.NoSuchElementException;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;


public class FXMLDocumentController implements Initializable {

@FXML
private TextField departureTime;

@FXML
private TextField flightNum;

@FXML
private TextField dest;

@FXML
private TextField flightDate;

@FXML
private TextField departureCity;

@FXML
private TextField arrivalTime;

@FXML 
private TextArea Output;

@FXML
void save(ActionEvent event) {

    String DepartureTime = departureTime.getText();
    String FlightNum = flightNum.getText();
    String Dest = dest.getText();
    String FlightDate = flightDate.getText();
    String ArrivalTime = arrivalTime.getText();
    String DepartureCity = departureCity.getText();

    try (Formatter output = new Formatter("flights.txt")) 
        {

                try 
                    {output.format("%s %s %s %s %s %s%n", FlightNum,     FlightDate, DepartureCity, Dest, DepartureTime, ArrivalTime);}
                catch (NoSuchElementException elementException) 
                    {Output.setText("Please fill out all fields.");}

        }
    catch (SecurityException | FileNotFoundException |     FormatterClosedException e)
        {
            e.printStackTrace();
        }

    Output.setText("Flight #" + FlightNum + " has been set.");


}

@Override
public void initialize(URL location, ResourceBundle resources) {
    throw new UnsupportedOperationException("Not supported yet."); //To         change body of generated methods, choose Tools | Templates.
}

}

我的fxml文件:

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.shape.*?>
<?import javafx.scene.text.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<AnchorPane id="AnchorPane" fx:id="root" prefHeight="462.0" prefWidth="473.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.101" fx:controller="projectaddflight.FXMLDocumentController">
    <children>
      <TextField fx:id="flightNum" layoutX="185.0" layoutY="86.0" />
      <Label layoutX="78.0" layoutY="91.0" text="Flight Number:" AnchorPane.rightAnchor="300.0" />
      <Label layoutX="67.0" layoutY="158.0" text="Destination City:" AnchorPane.rightAnchor="300.0" />
      <Label layoutX="77.0" layoutY="191.0" text="Departure City:" AnchorPane.rightAnchor="300.0" />
      <Label layoutX="68.0" layoutY="224.0" text="Departure Time:" AnchorPane.bottomAnchor="89.0" AnchorPane.leftAnchor="68.0" AnchorPane.rightAnchor="300.0" AnchorPane.topAnchor="224.0" />
      <Label layoutX="91.0" layoutY="224.0" text="Arrival Time:" AnchorPane.rightAnchor="299.0" />
      <TextField fx:id="dest" layoutX="185.0" layoutY="153.0" />
      <TextField fx:id="departureCity" layoutX="185.0" layoutY="186.0" />
      <TextField fx:id="departureTime" layoutX="185.0" layoutY="219.0" />
      <TextField fx:id="arrivalTime" layoutX="185.0" layoutY="252.0" />
      <Label layoutX="189.0" layoutY="22.0" text="Add a Flight">
         <font>
            <Font size="19.0" />
         </font>
      </Label>
      <Label layoutX="99.0" layoutY="125.0" text="Flight Date:" AnchorPane.rightAnchor="300.0" />
      <TextField fx:id="flightDate" layoutX="185.0" layoutY="120.0" />
      <Button layoutX="388.0" layoutY="279.0" mnemonicParsing="false" onAction="#save" text="Save" />
      <TextArea fx:id="Output" layoutX="41.0" layoutY="318.0" prefHeight="75.0" prefWidth="401.0" />
    </children>
</AnchorPane>

和我的文件

package projectaddflight;

import java.io.File;
import java.net.URL;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

/**
 *
 * @author Simca
 */
public class ProjectAddFlight extends Application {

    @Override
    public void start(Stage stage) throws Exception {
        URL url = new File("src/projectaddflight/FXMLDocument.fxml").toURL();
        Parent root = FXMLLoader.load(url);

        Scene scene = new Scene(root);

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

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

}

和错误代码:

Executing /Users/Simca/NetBeansProjects/projectAddFlight/dist/run1675277175/ProjectAddFlight.jar using platform /Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home/jre/bin/java
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$155(LauncherImpl.java:182)
    at java.lang.Thread.run(Thread.java:745)
Caused by: javafx.fxml.LoadException: 
/Users/Simca/NetBeansProjects/projectAddFlight/src/projectaddflight/FXMLDocument.fxml

    at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
    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 projectaddflight.ProjectAddFlight.start(ProjectAddFlight.java:25)
    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)
Caused by: java.lang.UnsupportedOperationException: Not supported yet.
    at projectaddflight.FXMLDocumentController.initialize(FXMLDocumentController.java:78)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
    ... 14 more
Exception running application projectaddflight.ProjectAddFlight
Java Result: 1
Deleting directory /Users/Simca/NetBeansProjects/projectAddFlight/dist/run1675277175
jfxsa-run:
BUILD SUCCESSFUL (total time: 2 seconds)

我尝试了各种方法来键入指向fxml文件的链接。我在网上看过,但没有看到这个确切的问题。在尝试找出该错误之前,它最初是通用的“ name” .java文件,甚至普通文件也无法正常工作。

0 个答案:

没有答案