运行 我的应用 returns 我:Javafx.fxml.LoadExeption

Running my app returns me : Javafx.fxml.LoadExeption

我的应用程序有问题。我正在尝试制作一个应用程序,它可以在命令提示符下完美运行,但具有漂亮的界面以获得更好的用户体验。为此,我选择了对我来说比 swing 更好的 Javafx。
但它不起作用。我不明白怎么了。 这是我的主要应用程序代码:

package ch.makery.adress;

import java.io.IOException;

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


public class MainApp extends Application {



    @Override
    public void start(Stage stage) throws Exception {
        Parent parent = FXMLLoader.load(getClass().getResource("PersonOverview.fxml"));
        Scene scene = new Scene(parent);
        stage.setTitle("Appication Extraction et remplissage Excel");
        stage.setScene(scene);
        stage.show();


}
}

我的 Hexacontroller:

package ch.makery.adress;

import java.awt.FileDialog;
import java.awt.List;
import java.io.File;
import java.io.IOException;
import javafx.fxml.Initializable;
import java.net.URL;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.ResourceBundle;
import javax.swing.JFrame;
import org.jdom2.Element;
import org.jdom2.input.SAXBuilder;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TextField;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import jxl.write.Label;
import jxl.write.WritableCell;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.Number;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;

public class HexaController implements Initializable {
    static org.jdom2.Document document;
    static JFrame fileDialog;
    static Element racine;
    static String Nom_dar;
    static java.util.List<Element> listeDAS;
    static ArrayList <String> Nom_das=new ArrayList();
    static ArrayList <String> Nom_task=new ArrayList();
    static ArrayList <String> Nom_Variable1=new ArrayList();
    static ArrayList <String> Resultat_Variable1=new ArrayList();
    static ArrayList <Double> Resultat_Variabledouble1=new ArrayList<Double>();
    static ArrayList <String> ResultatHexa_Variable1=new ArrayList<String>();
    static ArrayList <String> Lien=new ArrayList();
    static java.util.List<Element> ListeTRIAL;
    static java.util.List<Element> listeTASK;
    static java.util.List<Element> listeOperation;
    static List listeOperation_delta;
    static java.util.List<Element> listeArgument;
    static List listeArgument_delta;

        @FXML
        private ComboBox<String> hexa;
        ObservableList<String> list = FXCollections.observableArrayList();
        @FXML
        private TextField entree;

        @FXML
        private TextField nomfichier;

        @FXML
        private static TextField excel;

        @FXML
        private static TextField sortie;


        @FXML
        private void dar(ActionEvent event){
            FileDialog fd1=new FileDialog(fileDialog,"Choisissez un fichier .dar",FileDialog.LOAD);
            fd1.setDirectory("C:\");
            fd1.setVisible(true);
            String filename1=fd1.getFile();
            String Directory1=fd1.getDirectory();
            String path1=Directory1 + filename1;
            entree.setText(path1);
            nomfichier.setText(filename1);
        }

        @FXML
        private void modele(ActionEvent event){
            JFrame parentFrame=new JFrame();
             FileDialog filechooser = new FileDialog (parentFrame, "Choisir un modèle Excel à copier",FileDialog.LOAD);
             filechooser.setDirectory("C:\");
             filechooser.setVisible(true);
             String directory_copy = filechooser.getDirectory();
             String name_copy= filechooser.getFile();
             String path_copy = (directory_copy+name_copy);
             excel.setText(path_copy);
        }

        @FXML
        private void sortie (ActionEvent event){
            JFrame parentFrame2=new JFrame();
             FileDialog filechooser2 = new FileDialog (parentFrame2, "Choisir une destination d'enregistrement",FileDialog.SAVE);
             filechooser2.setDirectory("C:\");
             filechooser2.setVisible(true);
             String directory_save = filechooser2.getDirectory();
             String name_save= filechooser2.getFile();
             String path_save = (directory_save+name_save+".xls");
             sortie.setText(path_save);
        }
        @FXML
        private void annuler (ActionEvent event){
            System.exit(0);
        }


        @FXML
        private static ComboBox<Integer>methode;
        ObservableList<Integer>nombre = FXCollections.observableArrayList();

        @FXML
        private void exe (ActionEvent event) throws Throwable{
            SAXBuilder sxb = new SAXBuilder();
            String filename1=nomfichier.getText();
            if(filename1==null)
            {
                    System.out.println("Annulation");
                    System.exit(0);
            }
            else
            {
                try
                {
                    //On crée un nouveau document JDOM avec en argument le fichier XML
                    //Le parsing est terminé 
                    String path1=entree.getText();
                    document = sxb.build(new File(path1));
                    //On initialise un nouvel élément racine avec l'élément racine du document.
                    racine = document.getRootElement();
                    System.out.println("Lecture du premier .dar");
                }
                catch(Exception e)
                {
                    System.out.println("FATAL ERROR !");
                    System.exit(0);
                }
            }
            afficheALL();

            Xl();
        }


    //RECUPERATION DES DONNEES DU FICHIER DAR

        static void afficheALL()
        {
            //Variables Locales
            String Str;
            String Str_bis;
            Nom_dar=racine.getAttributeValue("label");

            System.out.println("Nom du fichier dar : " + Nom_dar+"\n");

            listeDAS= racine.getChildren("DAS");
            //On crée un Iterator sur notre liste
            Iterator<Element> i1 = listeDAS.iterator();

            ////TRAITEMENT POUR CHAQUE DAS
            String m[] = new String[50];
                m[0]="Marqueur de Sortie";
                m[1]="Nb Occurences";
                m[2]="Valeur Physique";
                m[3]="Résultat";
                m[4]="Valeur de Sortie";




                int s = methode.getValue();
                int n;
                for(n=5;n<5+s;n++)
                {

                    //System.out.println("Entrez le nom de la methode");
                    //Scanner methode = new Scanner(System.in);
                    //String name=methode.nextLine();
                    //m[n]=name;
                }
                int j;
                for(j=0;j<5+s;j++)
                {
                    System.out.println("Le nom de la methode "+j+" est :"+m[j]);
                }
            while(i1.hasNext())
            {
               Element courant = (Element)i1.next();
               //On affiche le nom de l’élément courant
               Str=courant.getAttributeValue("dasFullFileName").toString();
               System.out.println("Nom du DAS: " + Str);
               Nom_das.add(Str);

               ListeTRIAL=courant.getChildren("TRIAL");
               @SuppressWarnings("rawtypes")
            Iterator T1=ListeTRIAL.iterator();

               while(T1.hasNext())
               {
                 Element courant2 =(Element)T1.next();
                 Lien.add(courant2.getAttributeValue("xconvFullFileName").toString());
               }

               listeTASK=courant.getChildren("TASK");
               @SuppressWarnings("rawtypes")
            Iterator k1=listeTASK.iterator();


               while(k1.hasNext())
               {
                   Element courant2 =(Element)k1.next();
                   Str_bis=courant2.getAttributeValue("label").toString();
                   System.out.println(Str_bis);

                       listeOperation=courant2.getChildren("Operation");
                       @SuppressWarnings("rawtypes")
                    Iterator l1=listeOperation.iterator();

                        while(l1.hasNext())
                        {
                            Element courant3=(Element)l1.next();
                            listeArgument=courant3.getChildren("Argument");
                            @SuppressWarnings("rawtypes")
                            Iterator m1=listeArgument.iterator();

                            while(m1.hasNext())
                            {

                                Element courant4=(Element)m1.next();
                                int l;

                                for(l=0;l<5+s;l++)
                                {
                                    if(courant4.getAttributeValue("parameterName").compareTo(m[l])==0)
                                    {
                                        Nom_Variable1.add(courant4.getAttributeValue("argumentName"));
                                        double d = Double.parseDouble(courant4.getAttributeValue("instantValue"));
                                        DecimalFormat df = new DecimalFormat(".#");
                                        df.setMaximumFractionDigits(20);
                                        String sortie = df.format(d);
                                        long entier = (long)d;
                                        String hex = Long.toHexString(entier).toUpperCase();
                                        //hex.toUpperCase();
                                        Resultat_Variable1.add(sortie);
                                        Resultat_Variabledouble1.add(d);
                                        ResultatHexa_Variable1.add(hex);

                                    }
                                }
                            }
                        }
                    }
                    System.out.println("Fin lecture XML File");
               }
            }
        static void Xl() throws Throwable
         {

             try
             {

                 System.out.println("Saisi utilisateur ok");

        //CREATION DES FEUILLES NECESSAIRES A LA RECUPERATION DES DONNEES
                 String path_copy = excel.getText();
                 String path_save = sortie.getText();
                 Workbook copie = Workbook.getWorkbook(new File(path_copy));
                 WritableWorkbook sortie = Workbook.createWorkbook(new File(path_save),copie);
                 WritableFont bord=new WritableFont(WritableFont.ARIAL,11);
                 WritableCellFormat border=new WritableCellFormat(bord);


        //REMPLISSAGE DE LA PREMIERE FEUILLE AVEC LES DONNEES MESUREES
                 System.out.println("---"+Nom_Variable1.size()+"---");
                 for(int x=0;x<=Nom_Variable1.size()-1;x++)
                 {
                     Label Col0= new Label(0,x,Nom_Variable1.get(x),border);
                     sortie.getSheet(1).addCell(Col0);
                 }

                 for(int y=0;y<=Resultat_Variabledouble1.size()-1;y++)
                 {
                     Number Col1= new Number(1,y,Resultat_Variabledouble1.get(y),border);
                     sortie.getSheet(1).addCell((WritableCell) Col1);
                 }

                 for(int y=0;y<=ResultatHexa_Variable1.size()-1;y++)
                 {
                     Label Col2= new Label(2,y,ResultatHexa_Variable1.get(y),border);
                     sortie.getSheet(1).addCell(Col2);
                 }

                 System.out.println("Fin Copie Excel");
                 sortie.write();
                 sortie.close();

             }
             catch (RowsExceededException e1)
             {
             }
             catch(BiffException ex)
             {
             }
             catch (WriteException e1)
             {
             }
             catch (IOException e)
             {
             }
             finally
             {
                 System.out.println("Le fichier à été généré correctement.");
                 System.out.println ("Appuyez sur 'Entrée' pour terminer le programme");
                 System.exit(0);
            }

            System.exit(0);
         }

public HexaController(){

}

public void initialize(URL url,ResourceBundle rb){

    list.add(new String("OUI"));
    list.add(new String("NON"));
    hexa.setItems(list);
    nombre.add(new Integer(0));
    nombre.add(new Integer(1));
    nombre.add(new Integer(2));
    nombre.add(new Integer(3));
    nombre.add(new Integer(4));
    nombre.add(new Integer(5));
    methode.setItems(nombre);
}
}

还有我的 fxml 文件:

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

<?import javafx.scene.effect.*?>
<?import javafx.scene.text.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane prefHeight="350.0" prefWidth="720.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.makery.adress.HexaController">
   <children>
      <GridPane layoutX="-120.0" layoutY="-234.0" prefHeight="0.0" prefWidth="80.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
        <columnConstraints>
            <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
            <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
            <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
            <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
          <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
          <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
            <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
        </columnConstraints>
        <rowConstraints>
            <RowConstraints maxHeight="132.0" minHeight="10.0" prefHeight="64.0" vgrow="SOMETIMES" />
            <RowConstraints maxHeight="270.0" minHeight="0.0" prefHeight="52.0" vgrow="SOMETIMES" />
            <RowConstraints maxHeight="546.0" minHeight="10.0" prefHeight="61.0" vgrow="SOMETIMES" />
          <RowConstraints maxHeight="589.0" minHeight="10.0" prefHeight="76.0" vgrow="SOMETIMES" />
          <RowConstraints maxHeight="620.0" minHeight="10.0" prefHeight="63.0" vgrow="SOMETIMES" />
            <RowConstraints maxHeight="641.0" minHeight="10.0" prefHeight="47.0" vgrow="SOMETIMES" />
        </rowConstraints>
         <children>
            <Button mnemonicParsing="false" onAction="#dar" text="Parcourir" textAlignment="CENTER" GridPane.columnIndex="6" GridPane.halignment="CENTER" />
            <Button mnemonicParsing="false" onAction="#modele" text="Parcourir" textAlignment="CENTER" GridPane.columnIndex="6" GridPane.halignment="CENTER" GridPane.rowIndex="1" />
            <Button mnemonicParsing="false" onAction="#sortie" text="Enregistrer" textAlignment="CENTER" GridPane.columnIndex="6" GridPane.halignment="CENTER" GridPane.rowIndex="2" />
            <Button mnemonicParsing="false" onAction="#exe" text="Executer" GridPane.columnIndex="5" GridPane.halignment="CENTER" GridPane.rowIndex="5">
               <font>
                  <Font name="System Bold" size="12.0" />
               </font>
            </Button>
            <Button mnemonicParsing="false" onAction="#annuler" text="Annuler" GridPane.columnIndex="6" GridPane.halignment="CENTER" GridPane.rowIndex="5">
               <font>
                  <Font name="System Bold" size="12.0" />
               </font>
            </Button>
            <Label text="Choisissez un fichier &quot;.dar&quot;" GridPane.columnSpan="2" GridPane.halignment="LEFT">
               <GridPane.margin>
                  <Insets left="20.0" />
               </GridPane.margin>
            </Label>
            <Label text="Choisissez un modèle format &quot;.xls&quot;" GridPane.columnSpan="2" GridPane.halignment="LEFT" GridPane.rowIndex="1">
               <GridPane.margin>
                  <Insets left="20.0" />
               </GridPane.margin>
            </Label>
            <Label prefHeight="17.0" prefWidth="278.0" text="Choisissez la destination et le nom d'enregistrement" GridPane.columnSpan="3" GridPane.halignment="LEFT" GridPane.rowIndex="2">
               <GridPane.margin>
                  <Insets left="20.0" />
               </GridPane.margin>
            </Label>
            <Label text="Nombre de méthodes à ajouter" GridPane.columnSpan="2" GridPane.rowIndex="3">
               <padding>
                  <Insets left="20.0" />
               </padding>
            </Label>
            <Label text="Conversion hexadecimale" GridPane.columnSpan="2" GridPane.rowIndex="4">
               <padding>
                  <Insets left="20.0" />
               </padding>
            </Label>
            <TextField fx:id="entree" GridPane.columnIndex="3" GridPane.columnSpan="3" />
            <TextField fx:id="excel" GridPane.columnIndex="3" GridPane.columnSpan="3" GridPane.rowIndex="1" />
            <TextField fx:id="sortie" GridPane.columnIndex="3" GridPane.columnSpan="3" GridPane.rowIndex="2" />
            <ComboBox fx:id="methode" prefWidth="150.0" promptText="Choisir" GridPane.columnIndex="2" GridPane.rowIndex="3" />
            <ComboBox fx:id="hexa" prefWidth="150.0" promptText="Choisir" GridPane.columnIndex="2" GridPane.rowIndex="4" />
         </children>
      </GridPane>
   </children>
</AnchorPane>

当我 运行 出现这个错误时:

Exception in Application start method
Exception in thread "main" 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 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$launchApplication6(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: javafx.fxml.LoadException: 
/C:/workspace/Application_traitement/bin/ch/makery/adress/PersonOverview.fxml

    at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.load(Unknown Source)
    at ch.makery.adress.MainApp.start(MainApp.java:16)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication13(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait6(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$null4(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater5(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$null9(Unknown Source)
    ... 1 more
Caused by: java.lang.NullPointerException
    at ch.makery.adress.HexaController.initialize(HexaController.java:338)
    ... 18 more

你能帮我吗?
谢谢

您在 initialize() 方法中得到一个 NullPointerException。那是因为您的 ComboBox 方法被声明为静态的。

FXML 注入不适用于 JavaFX8 中的静态变量。

参考James_D对这个问题的回答:

javafx 8 compatibility issues - FXML static fields

public class HexaController implements Initializable {

    private org.jdom2.Document document;

    private JFrame fileDialog;
    private Element racine;
    private String Nom_dar;
    private java.util.List<Element> listeDAS;
    private ArrayList<String> Nom_das = new ArrayList();
    private ArrayList<String> Nom_task = new ArrayList();
    private ArrayList<String> Nom_Variable1 = new ArrayList();
    private ArrayList<String> Resultat_Variable1 = new ArrayList();
    private ArrayList<Double> Resultat_Variabledouble1 = new ArrayList<Double>();
    private ArrayList<String> ResultatHexa_Variable1 = new ArrayList<String>();
    private ArrayList<String> Lien = new ArrayList();
    private java.util.List<Element> ListeTRIAL;
    private java.util.List<Element> listeTASK;
    private java.util.List<Element> listeOperation;
    private List listeOperation_delta;
    private java.util.List<Element> listeArgument;
    private List listeArgument_delta;

    @FXML
    private ComboBox<String> hexa;
    ObservableList<String> list = FXCollections.observableArrayList();
    @FXML
    private TextField entree;

    @FXML
    private TextField nomfichier;

    @FXML
    private TextField excel;

    @FXML
    private TextField sortie;

    @FXML
    private void dar(ActionEvent event) {
        FileDialog fd1 = new FileDialog(fileDialog, "Choisissez un fichier .dar", FileDialog.LOAD);
        fd1.setDirectory("C:\");
        fd1.setVisible(true);
        String filename1 = fd1.getFile();
        String Directory1 = fd1.getDirectory();
        String path1 = Directory1 + filename1;
        entree.setText(path1);
        nomfichier.setText(filename1);
    }

    @FXML
    private void modele(ActionEvent event) {
        JFrame parentFrame = new JFrame();
        FileDialog filechooser = new FileDialog(parentFrame, "Choisir un modèle Excel à copier", FileDialog.LOAD);
        filechooser.setDirectory("C:\");
        filechooser.setVisible(true);
        String directory_copy = filechooser.getDirectory();
        String name_copy = filechooser.getFile();
        String path_copy = (directory_copy + name_copy);
        excel.setText(path_copy);
    }

    @FXML
    private void sortie(ActionEvent event) {
        JFrame parentFrame2 = new JFrame();
        FileDialog filechooser2 = new FileDialog(parentFrame2, "Choisir une destination d'enregistrement", FileDialog.SAVE);
        filechooser2.setDirectory("C:\");
        filechooser2.setVisible(true);
        String directory_save = filechooser2.getDirectory();
        String name_save = filechooser2.getFile();
        String path_save = (directory_save + name_save + ".xls");
        sortie.setText(path_save);
    }

    @FXML
    private void annuler(ActionEvent event) {
        System.exit(0);
    }

    @FXML
    private ComboBox<Integer> methode;
    ObservableList<Integer> nombre = FXCollections.observableArrayList();

    @FXML
    private void exe(ActionEvent event) throws Throwable {
        SAXBuilder sxb = new SAXBuilder();
        String filename1 = nomfichier.getText();
        if (filename1 == null) {
            System.out.println("Annulation");
            System.exit(0);
        } else {
            try {
                //On crée un nouveau document JDOM avec en argument le fichier XML
                //Le parsing est terminé 
                String path1 = entree.getText();
                document = sxb.build(new File(path1));
                //On initialise un nouvel élément racine avec l'élément racine du document.
                racine = document.getRootElement();
                System.out.println("Lecture du premier .dar");
            } catch (Exception e) {
                System.out.println("FATAL ERROR !");
                System.exit(0);
            }
        }
        afficheALL();

        Xl();
    }

    //RECUPERATION DES DONNEES DU FICHIER DAR
    private void afficheALL() {
        //Variables Locales
        String Str;
        String Str_bis;
        Nom_dar = racine.getAttributeValue("label");

        System.out.println("Nom du fichier dar : " + Nom_dar + "\n");

        listeDAS = racine.getChildren("DAS");
        //On crée un Iterator sur notre liste
        Iterator<Element> i1 = listeDAS.iterator();

        ////TRAITEMENT POUR CHAQUE DAS
        String m[] = new String[50];
        m[0] = "Marqueur de Sortie";
        m[1] = "Nb Occurences";
        m[2] = "Valeur Physique";
        m[3] = "Résultat";
        m[4] = "Valeur de Sortie";

        int s = methode.getValue();
        int n;
        for (n = 5; n < 5 + s; n++) {

            //System.out.println("Entrez le nom de la methode");
            //Scanner methode = new Scanner(System.in);
            //String name=methode.nextLine();
            //m[n]=name;
        }
        int j;
        for (j = 0; j < 5 + s; j++) {
            System.out.println("Le nom de la methode " + j + " est :" + m[j]);
        }
        while (i1.hasNext()) {
            Element courant = (Element) i1.next();
            //On affiche le nom de l’élément courant
            Str = courant.getAttributeValue("dasFullFileName").toString();
            System.out.println("Nom du DAS: " + Str);
            Nom_das.add(Str);

            ListeTRIAL = courant.getChildren("TRIAL");
            @SuppressWarnings("rawtypes")
            Iterator T1 = ListeTRIAL.iterator();

            while (T1.hasNext()) {
                Element courant2 = (Element) T1.next();
                Lien.add(courant2.getAttributeValue("xconvFullFileName").toString());
            }

            listeTASK = courant.getChildren("TASK");
            @SuppressWarnings("rawtypes")
            Iterator k1 = listeTASK.iterator();

            while (k1.hasNext()) {
                Element courant2 = (Element) k1.next();
                Str_bis = courant2.getAttributeValue("label").toString();
                System.out.println(Str_bis);

                listeOperation = courant2.getChildren("Operation");
                @SuppressWarnings("rawtypes")
                Iterator l1 = listeOperation.iterator();

                while (l1.hasNext()) {
                    Element courant3 = (Element) l1.next();
                    listeArgument = courant3.getChildren("Argument");
                    @SuppressWarnings("rawtypes")
                    Iterator m1 = listeArgument.iterator();

                    while (m1.hasNext()) {

                        Element courant4 = (Element) m1.next();
                        int l;

                        for (l = 0; l < 5 + s; l++) {
                            if (courant4.getAttributeValue("parameterName").compareTo(m[l]) == 0) {
                                Nom_Variable1.add(courant4.getAttributeValue("argumentName"));
                                double d = Double.parseDouble(courant4.getAttributeValue("instantValue"));
                                DecimalFormat df = new DecimalFormat(".#");
                                df.setMaximumFractionDigits(20);
                                String sortie = df.format(d);
                                long entier = (long) d;
                                String hex = Long.toHexString(entier).toUpperCase();
                                //hex.toUpperCase();
                                Resultat_Variable1.add(sortie);
                                Resultat_Variabledouble1.add(d);
                                ResultatHexa_Variable1.add(hex);

                            }
                        }
                    }
                }
            }
            System.out.println("Fin lecture XML File");
        }
    }

    private void Xl() throws Throwable {

        try {

            System.out.println("Saisi utilisateur ok");

            //CREATION DES FEUILLES NECESSAIRES A LA RECUPERATION DES DONNEES
            String path_copy = excel.getText();
            String path_save = sortie.getText();
            Workbook copie = Workbook.getWorkbook(new File(path_copy));
            WritableWorkbook sortie = Workbook.createWorkbook(new File(path_save), copie);
            WritableFont bord = new WritableFont(WritableFont.ARIAL, 11);
            WritableCellFormat border = new WritableCellFormat(bord);

            //REMPLISSAGE DE LA PREMIERE FEUILLE AVEC LES DONNEES MESUREES
            System.out.println("---" + Nom_Variable1.size() + "---");
            for (int x = 0; x <= Nom_Variable1.size() - 1; x++) {
                Label Col0 = new Label(0, x, Nom_Variable1.get(x), border);
                sortie.getSheet(1).addCell(Col0);
            }

            for (int y = 0; y <= Resultat_Variabledouble1.size() - 1; y++) {
                Number Col1 = new Number(1, y, Resultat_Variabledouble1.get(y), border);
                sortie.getSheet(1).addCell((WritableCell) Col1);
            }

            for (int y = 0; y <= ResultatHexa_Variable1.size() - 1; y++) {
                Label Col2 = new Label(2, y, ResultatHexa_Variable1.get(y), border);
                sortie.getSheet(1).addCell(Col2);
            }

            System.out.println("Fin Copie Excel");
            sortie.write();
            sortie.close();

        } catch (RowsExceededException e1) {
        } catch (BiffException ex) {
        } catch (WriteException e1) {
        } catch (IOException e) {
        } finally {
            System.out.println("Le fichier à été généré correctement.");
            System.out.println("Appuyez sur 'Entrée' pour terminer le programme");
            System.exit(0);
        }

        System.exit(0);
    }

    public HexaController() {

    }

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

        list.add(new String("OUI"));
        list.add(new String("NON"));
        hexa.setItems(list);
        nombre.add(new Integer(0));
        nombre.add(new Integer(1));
        nombre.add(new Integer(2));
        nombre.add(new Integer(3));
        nombre.add(new Integer(4));
        nombre.add(new Integer(5));
        methode.setItems(nombre);
    }

}

在您的 MainApp 中试试这个 class:

@Override
public void start(Stage stage) throws Exception {
    FXMLLoader loader = new FXMLLoader(getClass().getResource("PersonOverview.fxml"));
    Parent parent = (Parent)loader.load();
    Scene scene = new Scene(parent);
    stage.setTitle("Appication Extraction et remplissage Excel");
    stage.setScene(scene);
    stage.show();
    ((HexaController)loader.getController()).initForm();
}

然后在您的控制器中有一个名为 initForm() 的方法可以执行此操作:

public void initForm(){
    list.add(new String("OUI"));
    list.add(new String("NON"));
    hexa.setItems(list);
    nombre.add(new Integer(0));
    nombre.add(new Integer(1));
    nombre.add(new Integer(2));
    nombre.add(new Integer(3));
    nombre.add(new Integer(4));
    nombre.add(new Integer(5));
    methode.setItems(nombre);
}

同时删除控制器中的静态声明,它们不是必需的。您可以随心所欲地调用该方法,只需确保在调用 stage.show();

之后使用该方法