2015-06-06 46 views
0

JavaFX新手在這裏。我正在使用NetBeans 8.0 IDE,並將我的FXML文件RootLayout.fxml放入com.techie.java.view包中。我正在使用com.techie.java.controller包中聲明下面的代碼加載此FXML文件:JavaFX空指針異常:需要位置

private void initRootLayout() { 
    try { 
     pane = FXMLLoader.load(ContactManager.class.getResource("/view/RootLayout.fxml")); 

     Scene scene = new Scene(pane); 
     stage.setScene(scene); 
     stage.show(); 
    } catch (IOException ie) { 
     ie.printStackTrace(); 
    } 
} 

private void showPersonOverview() { 
    try { 
     AnchorPane anchorPane = FXMLLoader.load(ContactManager.class.getResource("/view/PersonOverview.fxml")); 

     pane.setCenter(anchorPane); 
    } catch (IOException ie) { 
     ie.printStackTrace(); 
    } 
} 

在執行我得到空指針異常的BorderPane pane = FXMLLoader.load(ContactManager.class.getResource("/view/RootLayout.fxml"));

我在做什麼錯?

+1

什麼行是錯誤發生在? – swingMan

+0

getResource()返回什麼? – fabian

回答

0

你需要

pane = FXMLLoader.load(
    ContactManager.class.getResource("/com/techie/java/view/RootLayout.fxml")); 

和類似的其他FXMLLoader