我运行的每个JavaFX应用程序都抛出两个NullPointerException异常。它们不会阻止甚至影响项目的执行,只有在调试模式下运行我的应用程序时,我才能看到它们。我甚至有这个问题与Oracle的HelloWorld示例,这最小的方案:JavaFX应用程序抛出NullPointerException异常但仍然运行
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);
}
}
这是第一个错误的堆栈跟踪:
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
这里是第二:
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
更重要的是,如果我删除的iAmRoot
和scene
(所以start()
只是读取primaryStage.show();
)任何情况下,不会出现第二个错误。这是为什么发生?
我已经能够在(JavaFX application throws NullPointerException at startup)之前找到此问题,但没有人似乎已经解决了它,并且它在2年前已被问到。
如果有帮助,我在Windows 7 Professional上运行Eclipse 4.5.2,并且我不认为我使用FXML。
编辑:
为它的价值,我找不到第二个错误的源代码,但我发现的JavaFX的代码会抛出的第一个错误(线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 }
现在回来了。但它仍然以张贴图像的形式出现,这些图像真的很难阅读......“Thread [Main](Suspended ...)”很奇怪。你在调试模式下运行这个吗? –
我将它重新格式化为代码,并在调试中运行它。这些错误根本无法处理,并且不会影响代码,所以要想看到它们的唯一方法就是以调试模式运行。 –
所以如果你正常运行它们,它们不会出现在控制台中? –