public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 300, 275));
primaryStage.show();
Platform.runLater(new Runnable() {
@Override public void run() {
Controller instance2 = new Controller();
instance2.aaa.setText("123");
}
});
}
public static void main(String[] args) {
launch(args);
}
}
public class Controller {
@FXML
Label aaa;
}
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at sample.Main$1.run(Main.java:22)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(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$147(WinApplication.java:177)
at java.lang.Thread.run(Thread.java:748)
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label fx:id="aaa" layoutX="164.0" layoutY="93.0" text="Label" />
</children>
</AnchorPane>
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at sample.Main$GlobalKeyListenerExample.lambda$nativeKeyReleased$0(Main.java:154)
public void nativeKeyReleased(NativeKeyEvent e) {
if (e.getKeyCode() == NativeKeyEvent.VC_F2) {
Controller.mediaPlayer.pause();
Duration ct = Controller.mediaPlayer.getCurrentTime();
Controller.mediaPlayer.seek(new Duration(ct.toMillis() - 1000));
Platform.runLater(() -> { Controller instance2 = new Controller();
//154 строка:
instance2.startonpause.setText("123"); });
}
}
Platform.runLater(new Runnable() {
@Override public void run() {
Controller instance = new Controller();
instance.startonpause.setText("12");
}
});
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at sample.Main$GlobalKeyListenerExample$1.run(Main.java:150)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(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$147(WinApplication.java:177)
at java.lang.Thread.run(Thread.java:748)
Controller instance = new Controller();
instance.play();
Exception in thread "JNativeHook Dispatch Thread" java.lang.IllegalStateException: Not on FX application thread; currentThread = JNativeHook Dispatch Thread
at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:279)
at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:423)
at javafx.stage.Stage.<init>(Stage.java:241)
at javafx.stage.Stage.<init>(Stage.java:227)
at javafx.scene.control.HeavyweightDialog$1.<init>(HeavyweightDialog.java:52)
at javafx.scene.control.HeavyweightDialog.<init>(HeavyweightDialog.java:52)
at javafx.scene.control.Dialog.<init>(Dialog.java:263)
at javafx.scene.control.Alert.<init>(Alert.java:245)
at javafx.scene.control.Alert.<init>(Alert.java:223)
at sample.Controller.<init>(Controller.java:35)
at sample.Main$GlobalKeyListenerExample.nativeKeyPressed(Main.java:114)
at org.jnativehook.GlobalScreen$EventDispatchTask.processKeyEvent(Unknown Source)
at org.jnativehook.GlobalScreen$EventDispatchTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Exception in thread "JNativeHook Dispatch Thread" java.lang.IllegalStateException: Not on FX application thread; currentThread = JNativeHook Dispatch Thread
at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:279)
at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:423)
at javafx.stage.Stage.<init>(Stage.java:241)
at javafx.stage.Stage.<init>(Stage.java:227)
at javafx.scene.control.HeavyweightDialog$1.<init>(HeavyweightDialog.java:52)
at javafx.scene.control.HeavyweightDialog.<init>(HeavyweightDialog.java:52)
at javafx.scene.control.Dialog.<init>(Dialog.java:263)
at javafx.scene.control.Alert.<init>(Alert.java:245)
at javafx.scene.control.Alert.<init>(Alert.java:223)
at sample.Controller.<init>(Controller.java:35)
at sample.Main$GlobalKeyListenerExample.nativeKeyPressed(Main.java:114)
at org.jnativehook.GlobalScreen$EventDispatchTask.processKeyEvent(Unknown Source)
at org.jnativehook.GlobalScreen$EventDispatchTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)