Tips about getting error java.lang.NullPointerException at NewJFrame.jButton4ActionPerformed(NewJFrame.java:2 66) when executing code
i think problem is from VBox or openwindow.getScene(). i use a button for brows and select a picture but when push that button openwindow.getScene() Returns the null value i see this error java.lang.NullPointerException at NewJFrame.jButton4ActionPerformed(NewJFrame.java:2 66)
i use java swing in gui add a jframe and in jframe add a button
FileChooser filechooser = new FileChooser(); public void initialize(URL location, ResourceBundle resourcr) { filechooser.setInitialDirectory(new File("user.home")); } private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: VBox openwindow = new VBox(); System.out.println(openwindow); Window stage = openwindow.getScene().getWindow(); filechooser.setTitle("Load Dialog"); filechooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("Picture File", "*.jpg"), new FileChooser.ExtensionFilter("Picture File", "*.png"), new FileChooser.ExtensionFilter("Picture File", "*.bmp")); try { File file = filechooser.showOpenDialog(stage); filechooser.setInitialDirectory(file.getParentFile()); } catch (Exception ex) { } }