How I load it:
public class App extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
FXMLLoader loader = new FXMLLoader();
Parent root = loader.load(new File("src/dreambot/guis/XPTracker.fxml").toURI().toURL());
Controller l = (Controller) loader.getControllerFactory();
primaryStage.setTitle("XP Tracker");
primaryStage.setScene(new Scene(root));
primaryStage.show();
l.setAtkXph(23233);
}
public void build(String[] args) {
launch(args);
}
}
Controller
public class Controller {
@FXML
Label atkXph;
public void setAtkXph(int num) {
atkXph.setText(num + "/h");
}
}
Main(String[] args) method
public class Tests {
public static void main(String[] args) {
new App().build(args);
}
}
The label in my fxml:
<Label id="atkXph" fx:id="atkXph" layoutX="68.0" layoutY="71.0" text="0/h" />
My error:
Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$159(LauncherImpl.java:182)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
at dreambot.main.App.start(App.java:23)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$166(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$179(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$177(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$178(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$152(WinApplication.java:177)
... 1 more