Bonjour,

J'essaye actuellement de développer une petite application avec JavaFx. Etant débutant, j'ai encore du mal à comprendre mes erreurs. J'espère que vous pourrez m'apporter votre aide. Voici mon code:

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
package com.jeremy;
 
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
 
import java.io.IOException;
 
public class Main extends Application {
 
    public static void main(String[] args) {
        launch(args);
    }
 
    @Override
    public void start(Stage primaryStage) throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("GUI/Office.fxml"));
        Scene scene = new Scene(root);
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}
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
package com.jeremy.GUI;
 
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.Initializable;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
 
import java.net.URL;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ResourceBundle;
 
import com.jeremy.Model.Client;
import com.jeremy.DAO.Database;
 
import javafx.scene.control.cell.PropertyValueFactory;
 
public class OfficeController implements Initializable {
 
 
    public TableView<Client> table;
    public TableColumn<Client, String> formation;
    public TableColumn<Client, String> lastName;
    public TableColumn<Client, String> firstName;
    public TableColumn<Client, String> email;
    public TableColumn<Client, String> phone;
 
    ObservableList<Client> obList = FXCollections.observableArrayList();
 
    @Override
    public void initialize(URL location, ResourceBundle resources) {
 
        Connection con = new Database().getConnection();
        try {
            ResultSet rs = con.createStatement().executeQuery("select * from registrations");
 
            while (rs.next()) {
                obList.add(new Client(rs.getString("formation"),
                            rs.getString("lastname"),
                            rs.getString("firstname"),
                            rs.getString("email"),
                            rs.getString("phone")
                            )
                );
 
            }
 
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
 
        formation.setCellValueFactory(new PropertyValueFactory<>("formation"));
        lastName.setCellValueFactory(new PropertyValueFactory<>("lastName"));
        firstName.setCellValueFactory(new PropertyValueFactory<>("firstName"));
        email.setCellValueFactory(new PropertyValueFactory<>("email"));
        phone.setCellValueFactory(new PropertyValueFactory<>("phone"));
 
        table.setItems(obList);
    }
}
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
<?xml version="1.0" encoding="UTF-8"?>
 
<?import java.net.URL?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
 
<AnchorPane prefHeight="681.0" prefWidth="1017.0" styleClass="bodybg" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.jeremy.GUI.OfficeController">
    <stylesheets>
        <URL value="@style.css" />
    </stylesheets>
   <children>
      <GridPane layoutX="140.0" layoutY="-26.0" prefHeight="629.0" prefWidth="764.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
        <columnConstraints>
          <ColumnConstraints hgrow="SOMETIMES" maxWidth="380.0" minWidth="10.0" prefWidth="239.0" />
          <ColumnConstraints halignment="CENTER" hgrow="SOMETIMES" maxWidth="778.0" minWidth="10.0" prefWidth="778.0" />
        </columnConstraints>
        <rowConstraints>
          <RowConstraints maxHeight="293.0" minHeight="10.0" prefHeight="74.0" vgrow="SOMETIMES" />
          <RowConstraints maxHeight="607.0" minHeight="10.0" prefHeight="607.0" vgrow="SOMETIMES" />
        </rowConstraints>
         <children>
            <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Panneau d'administration" wrappingWidth="438.8642578125" GridPane.columnIndex="1" GridPane.valignment="TOP">
               <font>
                  <Font size="39.0" />
               </font>
            </Text>
            <ImageView fitHeight="41.0" fitWidth="216.0" pickOnBounds="true" preserveRatio="true" GridPane.valignment="TOP">
               <image>
                  <Image url="@../Assets/logo.png" />
               </image>
            </ImageView>
            <TableView fx:id="table" maxHeight="-Infinity" maxWidth="-Infinity" prefHeight="552.0" prefWidth="746.0" GridPane.columnIndex="1" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="CENTER">
              <columns>
                <TableColumn fx:id="formation" prefWidth="200.0" text="Formation" />
                <TableColumn fx:id="lastName" prefWidth="100.0" text="Nom" />
                  <TableColumn fx:id="firstName" prefWidth="100.0" text="Prénom" />
                  <TableColumn fx:id="email" prefWidth="250.0" text="Email" />
                  <TableColumn fx:id="phone" prefWidth="95.0" text="Téléphone" />
              </columns>
            </TableView>
         </children>
      </GridPane>
   </children>
</AnchorPane>

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
package com.jeremy.DAO;
 
import java.sql.Connection;
import java.sql.DriverManager;
 
public class Database {
    public Connection getConnection()
    {
        try {
 
            String url = "jdbc:mysql://localhost:3308/lapasserelle?serverTimezone=UTC";
            Connection connection = DriverManager.getConnection(url,"root","");
 
            return connection;
 
        } catch (Exception e) {
            System.out.println("Error");
            System.out.println(e.getMessage());
        }
        return null;
    }
}
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
package com.jeremy.Model;
 
public class Client {
 
    String formation, lastName, firstName, email, phone;
 
    public Client(String formation, String lastName, String firstName, String email, String phone) {
        this.formation = formation;
        this.lastName = lastName;
        this.firstName = firstName;
        this.email = email;
        this.phone = phone;
    }
 
    public String getFormation() {
        return formation;
    }
 
    public void setFormation(String formation) {
        this.formation = formation;
    }
 
    public String getLastName() {
        return lastName;
    }
 
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
 
    public String getFirstName() {
        return firstName;
    }
 
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
 
    public String getEmail() {
        return email;
    }
 
    public void setEmail(String email) {
        this.email = email;
    }
 
    public String getPhone() {
        return phone;
    }
 
    public void setPhone(String phone) {
        this.phone = phone;
    }
}
Et voici l'erreur:

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
> Task :Main.main() FAILED
Exception in Application start method
Error
No suitable driver found for jdbc:mysql://localhost:3308/lapasserelle?serverTimezone=UTC
java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
	at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: javafx.fxml.LoadException: 
/C:/Users/jerem/OneDrive/Bureau/Projets/java/office/build/resources/main/com/jeremy/GUI/Office.fxml
 
Caused by: java.lang.RuntimeException: Exception in Application start method
 
	at javafx.fxml/javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2629)
	at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2607)
	at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2470)
	at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3241)
	at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3198)
	at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3167)
	at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3140)
	at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3117)
	at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:3110)
	at com.jeremy.Main.start(Main.java:19)
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
	at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
	at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
	at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
	at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
	at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
	at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
	... 1 more
Caused by: java.lang.NullPointerException
	at com.jeremy.GUI.OfficeController.initialize(OfficeController.java:37)
	at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2577)
	... 17 more
Exception running application com.jeremy.Main
 
Caused by: javafx.fxml.LoadException: 
 
Caused by: java.lang.NullPointerException
 
Execution failed for task ':Main.main()'.
> Process 'command 'C:/Program Files/AdoptOpenJDK/zulu14.fx/bin/java.exe'' finished with non-zero exit value 1
 
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

J'utilise IntelliJ comme IDE.

En vous remerciant d'avance pour votre aide.

Jérémy