Jede JavaFX-Anwendung, die ich ausgeführt habe, wirft zwei NullPointerExceptions. Sie verhindern oder beeinträchtigen nicht die Ausführung der Projekte und ich kann sie nur sehen, wenn ich meine Anwendungen im Debug-Modus laufe. Ich bin auch mit der Hello World Probe von Oracle dieses Problem habe und dieses Minimalprogramm:JavaFX-Anwendungen werfen NullPointerExceptions, aber laufen trotzdem
public class JavaFXTSample extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
StackPane iAmRoot = new StackPane();
Scene scene = new Scene(iAmRoot, 300, 250);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main (String[] args) {
launch(args);
}
}
Hier wird der Stack-Trace des ersten Fehlers:
Thread [main] (Suspended (exception NullPointerException))
SystemProperties.setVersions() line: 81 [local variables unavailable]
SystemProperties.lambda$static$28() line: 67
30621981.run() line: not available
AccessController.doPrivileged(PrivilegedAction<T>) line: not available [native method]
SystemProperties.<clinit>() line: 64
LauncherImpl.startToolkit() line: 668
LauncherImpl.launchApplicationWithArgs(String, String, String[]) line: 337
LauncherImpl.launchApplication(String, String, String[]) line: 328
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]
NativeMethodAccessorImpl.invoke(Object, Object[]) line: not available
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: not available
Method.invoke(Object, Object...) line: not available
LauncherHelper$FXHelper.main(String...) line: not available
Und hier ist die zweite:
Thread [JavaFX Application Thread] (Suspended (exception NullPointerException))
PropertyHelper.lambda$getBooleanProperty$514(String) line: 39
7164036.run() line: not available
AccessController.doPrivileged(PrivilegedAction<T>) line: not available [native method]
PropertyHelper.getBooleanProperty(String) line: 37
Parent.<clinit>() line: 87
JavaFXTSample.start(Stage) line: 16
LauncherImpl.lambda$launchApplication1$162(AtomicBoolean, Application) line: 863
2266602.run() line: not available
PlatformImpl.lambda$runAndWait$175(Runnable, CountDownLatch) line: 326
32251660.run() line: not available
PlatformImpl.lambda$null$173(Runnable) line: 295
11305869.run() line: not available
AccessController.doPrivileged(PrivilegedAction<T>, AccessControlContext) line: not available [native method]
PlatformImpl.lambda$runLater$174(Runnable, AccessControlContext) line: 294
30052382.run() line: not available
InvokeLaterDispatcher$Future.run() line: 95
WinApplication._runLoop(Runnable) line: not available [native method]
WinApplication.lambda$null$148(int, Runnable) line: 191
32126786.run() line: not available
Thread.run() line: not available
Was mehr ist, wenn ich eine Instanz von iAmRoot
und scene
entfernen (so start()
gerade lesen primaryStage.show();
), der zweite Fehler tritt nicht auf. Warum passiert dies?
Ich konnte diese Frage vor (JavaFX application throws NullPointerException at startup) finden, aber niemand scheint es gelöst zu haben, und es wurde vor über 2 Jahren gefragt.
Wenn es hilft, ich laufen Eclipse 4.5.2 auf Windows 7 Professional, und ich glaube nicht, dass ich FXML überhaupt verwende.
EDIT:
für das, was es wert ist, kann ich nicht den Quellcode für den zweiten Fehler finden, aber ich fand die Methode JavaFX den Code, der den ersten Fehler auslöst (Linie 81):
58 private static final String versionResourceName =
59 "/com/sun/javafx/runtime/resources/version.properties";
...
78 private static void setVersions() {
79 int size;
80 InputStream is =
81 SystemProperties.class.getResourceAsStream(versionResourceName);
82 try {
83 size = is.available();
84
85 byte[] b = new byte[size];
86 int n = is.read(b);
87 String inStr = new String(b, "utf-8");
88 SystemProperties.setFXProperty("javafx.version",
89 getValue(inStr, "release="));
90
91 SystemProperties.setFXProperty("javafx.runtime.version",
92 getValue(inStr, "full="));
93
94 } catch (Exception ignore) {
95 }
96 }
Es ist jetzt zurück. Aber es wird immer noch als Bilder gepostet, die wirklich schwer zu lesen sind ... "Thread [Main] (Suspended ...)" ist seltsam. Führen Sie dies im Debug-Modus aus? –
Ich habe es als Code umformatiert, und ich führe es in Debug. Diese Fehler werden überhaupt nicht behandelt, und sie haben keinen Einfluss auf den Code. Daher ist die einzige Möglichkeit, sie zu sehen, der Debug-Modus. –
Also, wenn Sie es normal ausführen, erscheinen sie nicht in der Konsole? –