0

I try to use JavaFX to build a GUI. When I initialize the table with the two columns, roomId and applianceId, there is a error.

@FXML
private void initialize() {
    // Initialize the appliance table with the two columns.
    roomIdColumn.setCellValueFactory(cellData -> cellData.getValue().roomIdProperty());
    applianceIdColumn.setCellValueFactory(cellData -> cellData.getValue().applianceIdProperty());
}

Following is the appliance class

private IntegerProperty applianceId;
private IntegerProperty roomId;
private IntegerProperty state;

public Appliance(int applianceId, Integer roomId) {
    this.applianceId = new SimpleIntegerProperty(applianceId);  
    this.roomId = new SimpleIntegerProperty(roomId);
    this.state = new SimpleIntegerProperty(0);
    System.out.println("Room " + roomId + "  Appliance " + applianceId + " created");
}

public IntegerProperty roomIdProperty() {
    return roomId;
}

public int getApplianceId() {
    return applianceId.get();
}

public IntegerProperty applianceIdProperty() {
    return applianceId;
}

public abstract int getPower();

public IntegerProperty getState(){
    System.out.println("appliance " + applianceId + " state = " + state);
    return this.state;
}

The error shows:

    javafx.fxml.LoadException:
    at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2605)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2575)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2445)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2413)
    at view.MainApplication.showApplicationOverview(MainApplication.java:89)
    at view.MainApplication.start(MainApplication.java:59)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$159(LauncherImpl.java:863)
    at com.sun.javafx.application.LauncherImpl$$Lambda$54/365777365.run(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$172(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl$$Lambda$47/186276003.run(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$null$170(PlatformImpl.java:295)
    at com.sun.javafx.application.PlatformImpl$$Lambda$49/2058173423.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(PlatformImpl.java:294)
    at com.sun.javafx.application.PlatformImpl$$Lambda$48/237061348.run(Unknown Source)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
Caused by: 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:497)
    at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2570)
    ... 14 more
Caused by: java.lang.NullPointerException
    at view.ApplicationOverviewControl.initialize(ApplicationOverviewControl.java:46)
    ... 24 more

Why the initialize method run in error? I just follow a tutorial on the web and change some identifiers. It seems that some thing wrong in roomIdProperty() and applianceIdProperty().

Helen
  • 77
  • 1
  • 4
  • 13
  • Either `roomIdColumn` or `applianceIdColumn` is null. – James_D Dec 11 '15 at 14:25
  • Got it. Thx. What about the error java.lang.reflect.InvocationTargetException? – Helen Dec 11 '15 at 14:55
  • That is just an exception wrapping the null pointer exception. If you fix the null pointer exception (presumably a problem with your FXML injection or `fx:id` attributes, but you didn't show the code), then the rest goes away. – James_D Dec 11 '15 at 14:56
  • Yes. I put the wrong fx:id. Thank you:) – Helen Dec 11 '15 at 15:28

0 Answers0