JavaFX TableView mit Daten aus der Datenbank füllen?

regex9  01.01.2022, 21:18

Gibt es ein TableColumn-Element mit gleichnamiger ID (idCol) in deinem FXML View?

Brunoo123 
Fragesteller
 01.01.2022, 21:35

nein, diesen Namen habe ich einmalig vergeben

2 Antworten

Wo wird denn printUsers aufgerufen?

Ist die .fxml Datei korrekt angelegt?

https://stackoverflow.com/questions/44909590/javafx-tablecolumn-setcellvaluefactory-throws-null-pointer

Brunoo123 
Fragesteller
 01.01.2022, 21:34

Die wird in der Main Klasse aufgerufen:

public class Main extends Application {
    @Override
    public void start(Stage stage) {
        try {
            //FXMLLoader fxmlLoader = new FXMLLoader(HomeController.class.getResource("/view/homeView.fxml"));
            //FXMLLoader fxmlLoader = new FXMLLoader(AddUserController.class.getResource("/view/settingView/addUserView.fxml"));
            FXMLLoader fxmlLoader = new FXMLLoader(AddUserController.class.getResource("/view/settingView/userView.fxml"));
            Scene scene = new Scene(fxmlLoader.load());
            stage.setResizable(false);
            stage.setTitle("Worktime Tracker");
            stage.setScene(scene);
            stage.show();
            UserController userController = new UserController();
            userController.printUser();
        }catch (Exception exception) {
            System.out.println(exception.getMessage());
        }
    }
}

Ja

0
regex9  01.01.2022, 21:41
@Brunoo123

Deine UserController-Instanz hat so keine Bindung zu einer View. Hole sie dir vom FXMLLoader.

UserController controller = (UserController) fxmlLoader.getController();
2
Brunoo123 
Fragesteller
 01.01.2022, 21:46
@regex9

Danke für die Antwort.

Das hat mir ein bisschen weitergeholfen aber ich bekomme jetzt eine andere Fehlermeldung:

java.lang.NullPointerException: Cannot invoke "controller.settingController.UserController.printUser()" because "controller" is null

at Main.start(Main.java:23)

at javafx.graphics@18-ea/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)

at javafx.graphics@18-ea/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)

at javafx.graphics@18-ea/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)

at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)

at javafx.graphics@18-ea/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)

at javafx.graphics@18-ea/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)

at javafx.graphics@18-ea/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)

at javafx.graphics@18-ea/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)

at java.base/java.lang.Thread.run(Thread.java:833)

0
Brunoo123 
Fragesteller
 01.01.2022, 21:50
@Brunoo123

Danke für euere Hilfe. Es hat geklappt.

Danke noch mal :)

0
regex9  01.01.2022, 21:52
@Brunoo123

Hast du denn im Root-Element deiner FXML den Controller definiert?

0

In deiner FXML-Datei muss es ein TableColumn-Element mit einer ID idCol geben. Ohne deren Existenz kann kein Element auf dein Feld idCol gemappt werden.