Bonjour,
Je me trouve avec un controller null mais je ne comprends pas pourquoi car mon loader lui n'est pas null !
Ce problème survient alors que j'ai ajouté un tabPane dans le RootLayout.fxml.
Quelqu'un saurait-il m'aiguiller s'il vous plaît ?
Cette exception se produit à la ligne 89 de ma classe MainApp.java :
et voici la AdherentsOverviewLayout.fxml :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103 package saubens.ecole.adherents; import java.io.IOException; import javafx.application.Application; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.BorderPane; import javafx.stage.Stage; import saubens.ecole.adherents.model.Eleve; import saubens.ecole.adherents.model.Elu; import saubens.ecole.adherents.model.Personne; import saubens.ecole.adherents.model.Professeur; import saubens.ecole.adherents.view.PersonneOverviewControleur; import saubens.ecole.adherents.view.beans.AdherentsOverviewBean; public class MainApp extends Application { private Stage primaryStage; private BorderPane rootLayout; // The data as an observable list of Personne private ObservableList<AdherentsOverviewBean> personnes = FXCollections.observableArrayList(); public ObservableList<AdherentsOverviewBean> getPersonnes() {return personnes;} //CONSTRUCTEUR public MainApp() { // Add some sample data Elu elu1 = new Elu("Calestroupat", "prenom1", 35, 1, null, null, null, null, null, null, "PRESIDENT"); Elu elu2 = new Elu("nom2", "prenom2", 43, 6, null, null, null, null, null, null, "TRESORIER"); Professeur prof1 = new Professeur("nom3", "prenom3", 42, 2, null, null, null, null, null, null, "BATTERIE", "SOLFEGE"); Professeur prof2 = new Professeur("nom4", "prenom4", 17, 2, null, null, null, null, null, null, "PIANO", null); Eleve el1 = new Eleve("nom5", "prenom5", 42, 2, null, null, null, null, null, null, "BATTERIE"); Eleve el2 = new Eleve("nom6", "prenom6", 37, 4, null, null, null, null, null, null, "PIANO"); personnes.add(elu1.getBean()); personnes.add(elu2.getBean()); personnes.add(prof1.getBean()); personnes.add(prof2.getBean()); personnes.add(el1.getBean()); personnes.add(el2.getBean()); } @Override public void start(Stage primaryStage) { this.primaryStage = primaryStage; this.primaryStage.setTitle("Ecole de musique de Saubens"); initRootLayout(); showAdherentsOverview(); } // 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 = (BorderPane) loader.load(); // Show the scene containing the root layout. Scene scene = new Scene(rootLayout); primaryStage.setScene(scene); primaryStage.show(); } catch (IOException e) { e.printStackTrace(); } } // Shows the adherents overview inside the root layout. public void showAdherentsOverview() { try { // Load adherents overview. FXMLLoader loader = new FXMLLoader(); loader.setLocation(MainApp.class.getResource("view/AdherentsOverview.fxml")); AnchorPane adherentsOverview = (AnchorPane) loader.load(); // Set adherents overview into the center of root layout. rootLayout.setCenter(adherentsOverview); // Give the controller access to the main app. PersonneOverviewControleur controleur = loader.getController(); controleur.setMainApp(this); } catch (IOException e) { e.printStackTrace(); } } // Returns the main stage. public Stage getPrimaryStage() { return primaryStage; } public static void main(String[] args) { launch(args); } }
Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102 <?xml version="1.0" encoding="UTF-8"?> <?import javafx.scene.control.Button?> <?import javafx.scene.control.ButtonBar?> <?import javafx.scene.control.CheckBox?> <?import javafx.scene.control.Label?> <?import javafx.scene.control.SplitPane?> <?import javafx.scene.control.TableColumn?> <?import javafx.scene.control.TableView?> <?import javafx.scene.layout.AnchorPane?> <?import javafx.scene.layout.ColumnConstraints?> <?import javafx.scene.layout.GridPane?> <?import javafx.scene.layout.Pane?> <?import javafx.scene.layout.RowConstraints?> <AnchorPane prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.72" xmlns:fx="http://javafx.com/fxml/1"> <children> <SplitPane dividerPositions="0.5" layoutX="87.0" layoutY="193.0" prefHeight="600.0" prefWidth="800.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <items> <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0"> <children> <Pane layoutX="57.0" layoutY="33.0" prefHeight="90.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <children> <CheckBox layoutX="9.0" layoutY="9.0" mnemonicParsing="false" text="Eleves" /> <CheckBox layoutX="9.0" layoutY="36.0" mnemonicParsing="false" text="Professeurs" /> <CheckBox layoutX="9.0" layoutY="66.0" mnemonicParsing="false" text="Bureau" /> </children> </Pane> <TableView fx:id="personneTable" layoutX="17.0" layoutY="208.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="90.0"> <columns> <TableColumn minWidth="80.0" prefWidth="100.0" text="Nom" /> <TableColumn minWidth="50.0" prefWidth="75.0" text="Prenom" /> <TableColumn minWidth="50.0" prefWidth="90.0" text="Instrument" /> <TableColumn minWidth="50.0" text="Fonction" /> <TableColumn minWidth="50.0" prefWidth="75.0" text="Matière" /> </columns> </TableView> </children> </AnchorPane> <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0"> <children> <GridPane layoutX="98.0" layoutY="171.0" prefHeight="427.0" prefWidth="385.0" AnchorPane.bottomAnchor="121.0" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="50.0"> <columnConstraints> <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> </columnConstraints> <rowConstraints> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> </rowConstraints> <children> <Label text="Nom" /> <Label text="Label" GridPane.columnIndex="1" /> <Label text="Prénom" GridPane.rowIndex="1" /> <Label text="Label" GridPane.columnIndex="1" GridPane.rowIndex="1" /> <Label text="Adresse" GridPane.rowIndex="2" /> <Label text="Label" GridPane.columnIndex="1" GridPane.rowIndex="2" /> <Label text="Email" GridPane.rowIndex="3" /> <Label text="Label" GridPane.columnIndex="1" GridPane.rowIndex="3" /> <Label text="Tel 1" GridPane.rowIndex="4" /> <Label text="Label" GridPane.columnIndex="1" GridPane.rowIndex="4" /> <Label text="Tel 2" GridPane.rowIndex="5" /> <Label text="Label" GridPane.columnIndex="1" GridPane.rowIndex="5" /> <Label text="Genre" GridPane.rowIndex="6" /> <Label text="Label" GridPane.columnIndex="1" GridPane.rowIndex="6" /> <Label text="Age" GridPane.rowIndex="7" /> <Label text="Date naissance" GridPane.rowIndex="8" /> <Label text="Label" GridPane.columnIndex="1" GridPane.rowIndex="7" /> <Label text="Label" GridPane.columnIndex="1" GridPane.rowIndex="8" /> <Label text="Instrument" GridPane.rowIndex="10" /> <Label text="Matière" GridPane.rowIndex="11" /> <Label text="Label" GridPane.columnIndex="1" GridPane.rowIndex="9" /> <Label text="Ancienneté" GridPane.rowIndex="9" /> <Label text="Label" GridPane.columnIndex="1" GridPane.rowIndex="10" /> <Label text="Label" GridPane.columnIndex="1" GridPane.rowIndex="11" /> <Label text="Fonction" GridPane.rowIndex="12" /> <Label text="Label" GridPane.columnIndex="1" GridPane.rowIndex="12" /> </children> </GridPane> <ButtonBar layoutX="169.0" layoutY="536.0" prefHeight="40.0" prefWidth="326.0" AnchorPane.bottomAnchor="5.0" AnchorPane.rightAnchor="5.0"> <buttons> <Button mnemonicParsing="false" text="Nouveau" /> <Button mnemonicParsing="false" text="Editer" /> <Button mnemonicParsing="false" text="Supprimer" /> </buttons> </ButtonBar> </children></AnchorPane> </items> </SplitPane> </children> </AnchorPane>
Et la RootLayout.fxml :
Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143 <?xml version="1.0" encoding="UTF-8"?> <?import javafx.scene.control.Button?> <?import javafx.scene.control.ButtonBar?> <?import javafx.scene.control.CheckBox?> <?import javafx.scene.control.Label?> <?import javafx.scene.control.Menu?> <?import javafx.scene.control.MenuBar?> <?import javafx.scene.control.MenuItem?> <?import javafx.scene.control.SplitPane?> <?import javafx.scene.control.Tab?> <?import javafx.scene.control.TabPane?> <?import javafx.scene.control.TableColumn?> <?import javafx.scene.control.TableView?> <?import javafx.scene.layout.AnchorPane?> <?import javafx.scene.layout.BorderPane?> <?import javafx.scene.layout.ColumnConstraints?> <?import javafx.scene.layout.GridPane?> <?import javafx.scene.layout.Pane?> <?import javafx.scene.layout.RowConstraints?> <BorderPane prefHeight="700.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.72" xmlns:fx="http://javafx.com/fxml/1" fx:controller="saubens.ecole.adherents.view.PersonneOverviewControleur"> <top> <MenuBar BorderPane.alignment="CENTER"> <menus> <Menu mnemonicParsing="false" text="File"> <items> <MenuItem mnemonicParsing="false" text="Close" /> </items> </Menu> <Menu mnemonicParsing="false" text="Edit"> <items> <MenuItem mnemonicParsing="false" text="Delete" /> </items> </Menu> <Menu mnemonicParsing="false" text="Help"> <items> <MenuItem mnemonicParsing="false" text="About" /> </items> </Menu> </menus> </MenuBar> </top> <center> <TabPane prefHeight="200.0" prefWidth="200.0" tabClosingPolicy="UNAVAILABLE" BorderPane.alignment="CENTER"> <tabs> <Tab text="Répertoire"> <content> <AnchorPane prefHeight="600.0" prefWidth="800.0"> <children> <SplitPane dividerPositions="0.5" layoutX="87.0" layoutY="193.0" prefHeight="600.0" prefWidth="800.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <items> <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0"> <children> <Pane layoutX="57.0" layoutY="33.0" prefHeight="90.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <children> <CheckBox layoutX="9.0" layoutY="9.0" mnemonicParsing="false" text="Eleves" /> <CheckBox layoutX="9.0" layoutY="36.0" mnemonicParsing="false" text="Professeurs" /> <CheckBox layoutX="9.0" layoutY="66.0" mnemonicParsing="false" text="Bureau" /> </children> </Pane> <TableView fx:id="personneTable" layoutX="17.0" layoutY="208.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="90.0"> <columns> <TableColumn fx:id="nomColumn" minWidth="80.0" prefWidth="100.0" text="Nom" /> <TableColumn fx:id="prenomColumn" minWidth="50.0" prefWidth="75.0" text="Prenom" /> <TableColumn fx:id="instrumentColumn" minWidth="50.0" prefWidth="90.0" text="Instrument" /> <TableColumn fx:id="fonctionColumn" minWidth="50.0" text="Fonction" /> <TableColumn fx:id="matiereColumn" minWidth="50.0" prefWidth="75.0" text="Matière" /> </columns> </TableView> </children> </AnchorPane> <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0"> <children> <GridPane layoutX="98.0" layoutY="171.0" prefHeight="427.0" prefWidth="385.0" AnchorPane.bottomAnchor="121.0" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="50.0"> <columnConstraints> <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> </columnConstraints> <rowConstraints> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> </rowConstraints> <children> <Label text="Nom" /> <Label text="Label" GridPane.columnIndex="1" /> <Label text="Prénom" GridPane.rowIndex="1" /> <Label text="Label" GridPane.columnIndex="1" GridPane.rowIndex="1" /> <Label text="Adresse" GridPane.rowIndex="2" /> <Label text="Label" GridPane.columnIndex="1" GridPane.rowIndex="2" /> <Label text="Email" GridPane.rowIndex="3" /> <Label text="Label" GridPane.columnIndex="1" GridPane.rowIndex="3" /> <Label text="Tel 1" GridPane.rowIndex="4" /> <Label text="Label" GridPane.columnIndex="1" GridPane.rowIndex="4" /> <Label text="Tel 2" GridPane.rowIndex="5" /> <Label text="Label" GridPane.columnIndex="1" GridPane.rowIndex="5" /> <Label text="Genre" GridPane.rowIndex="6" /> <Label text="Label" GridPane.columnIndex="1" GridPane.rowIndex="6" /> <Label text="Age" GridPane.rowIndex="7" /> <Label text="Date naissance" GridPane.rowIndex="8" /> <Label text="Label" GridPane.columnIndex="1" GridPane.rowIndex="7" /> <Label text="Label" GridPane.columnIndex="1" GridPane.rowIndex="8" /> <Label text="Instrument" GridPane.rowIndex="10" /> <Label text="Matière" GridPane.rowIndex="11" /> <Label text="Label" GridPane.columnIndex="1" GridPane.rowIndex="9" /> <Label text="Ancienneté" GridPane.rowIndex="9" /> <Label text="Label" GridPane.columnIndex="1" GridPane.rowIndex="10" /> <Label text="Label" GridPane.columnIndex="1" GridPane.rowIndex="11" /> <Label text="Fonction" GridPane.rowIndex="12" /> <Label text="Label" GridPane.columnIndex="1" GridPane.rowIndex="12" /> </children> </GridPane> <ButtonBar layoutX="169.0" layoutY="536.0" prefHeight="40.0" prefWidth="326.0" AnchorPane.bottomAnchor="5.0" AnchorPane.rightAnchor="5.0"> <buttons> <Button mnemonicParsing="false" text="Nouveau" /> <Button mnemonicParsing="false" text="Editer" /> <Button mnemonicParsing="false" text="Supprimer" /> </buttons> </ButtonBar> </children> </AnchorPane> </items> </SplitPane> </children> </AnchorPane> </content> </Tab> <Tab text="Budget" /> </tabs> </TabPane> </center> </BorderPane>
Merci,
Partager