/ / javafx Wie macht man ein Panel öffentlich statisch? [duplizieren] - Java, Javafx, Javafx-2, Javafx-8

javafx: So machen Sie ein Panel statisch [Duplikat] - Java, Javafx, Javafx-2, Javafx-8

während ich versuche, ein Panel statisch zu machen, zeigt es keinen Fehler beim Kompilieren, aber während der Laufzeit gibt es einen Fehler wie:

Exception in Application start method
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:483)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:367)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:305)
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:483)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:894)
at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:56)
at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:158)
at java.lang.Thread.run(Thread.java:745)
Caused by: javafx.fxml.LoadException:
unknown path

at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2617)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2595)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2425)
at schoolmanagement2.SchoolManagement2.start(SchoolManagement2.java:32)
at com.sun.javafx.application.LauncherImpl$8.run(LauncherImpl.java:837)
at com.sun.javafx.application.PlatformImpl$7.run(PlatformImpl.java:335)
at com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:301)
at com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:298)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$6.run(PlatformImpl.java:298)
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.access$300(WinApplication.java:39)
at com.sun.glass.ui.win.WinApplication$4$1.run(WinApplication.java:112)
... 1 more

Ich möchte wissen, warum dieser Fehler ausgegeben wird

Hilf mir bitte...

und ist es möglich, ein Panel statisch zu machen oder nicht.

Vielen Dank.

Antworten:

0 für die Antwort № 1

Dies war in JFX 2 möglich. In JFX 8 wurde diese Funktionalität entfernt.

Sie können es nicht tun.

Sie können eine andere Variable erstellen, die statisch istist gleich diesem nicht statischen Bereich. Das ist möglich. Sie müssen Ihre neue statische Variable jedoch manuell so einstellen, dass sie während des Starts oder der Initialisierungsmethode mit Ihrer nicht statischen Variablen übereinstimmt. Besser noch, erstellen Sie einen statischen Verweis auf diese Instanz der Klasse in Ihrer Klasse. So wie:

private static Controller instance;

Und initialisieren Sie es, während Sie die Methoden erneut starten oder initialisieren. Dann können Sie darauf verweisen mit:

Controller.instance.panel.doSomething();