2017-06-21 88 views
9

我運行的每個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  

更重要的是,如果我刪除的iAmRootscene(所以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 } 
+0

現在回來了。但它仍然以張貼圖像的形式出現,這些圖像真的很難閱讀......「Thread [Main](Suspended ...)」很奇怪。你在調試模式下運行這個嗎? –

+0

我將它重新格式化爲代碼,並在調試中運行它。這些錯誤根本無法處理,並且不會影響代碼,所以要想看到它們的唯一方法就是以調試模式運行。 –

+1

所以如果你正常運行它們,它們不會出現在控制檯中? –

回答

0

我試過你的第一個例子的代碼,並且工作正常。也許看看這裏,從下面的鏈接克隆代碼並嘗試。它包含maven構建。

https://github.com/johanwitters/stackoverflow.javafx-nullpointer

我把斷點在每一行,運行調試,所有斷點之間玩。結果:沒有問題。都好。也許你的環境有問題?

希望這會有所幫助。

相關問題