-2

In this design, when I try and delete the VBox from the parent node which is an HBox, I see that the VBox node is removed from the scene, however, it throws a NullPointerException after deleting the element.

Would appreciate any helps...

this is my main controller that has tabs

public class WorkspaceController {
    private HBox container;
    private ScrollPane scrollPane;

    public WorkspaceController(Stage stage, Project project) {
        this.stage = stage;
        this.project = project;
    }

    @FXML
    public void initialize() { setupTabs(); }

    private void setupTabs() {
        Tab tab = new Tab(project.getName());
        container = new HBox(10);
        scrollPane = new ScrollPane();
        for (Column column : project.getColumns()) {
            createColumns(tab, column, container);
        }
        tabPane.getTabs().add(tab);
    }
    public void createColumns(Tab tab, Column column, HBox container) {
        ColumnController col = new ColumnController(column, this);
        container.getChildren().add(col);
        scrollPane.setContent(container);
        tab.setContent(sp);
    }
    public void deleteColumn(VBox vbox) {
        Tab tab = tabPane.getSelectionModel().getSelectedItem();
        sp = (ScrollPane) tab.getContent();
        container = (HBox) sp.getContent();
        container.getChildren().remove(vbox);
    }
}

This is my ColumnController that extends VBox

public class ColumnController extends VBox {

    public ColumnController(Column column, WorkspaceController parentController) {
        this.column = column;
        this.parent = parentController;
        
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/view/ColumnView.fxml"));
        fxmlLoader.setRoot(this);
        fxmlLoader.setController(this);

        try {
            fxmlLoader.load();
        } catch (IOException exception) {
            throw new RuntimeException(exception);
        }
    }

    @FXML
    public void initialize() {
        columnName.setText(column.getName());
        this.setId(column.getName());
        deleteColumn.setOnAction(e -> {
            this.parent.deleteColumn(this);
        });
    }
}

StackTrace

Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
    at java.base/java.util.Objects.requireNonNull(Objects.java:208)
    at javafx.controls/javafx.scene.control.skin.MenuButtonSkinBase.lambda$new$7(MenuButtonSkinBase.java:206)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:447)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:446)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
  • 2
    [mcve] please .. including application, controller, fxml and complete stacktrace (but still minding the __M__ - nothing unrelated to the problem :) – kleopatra Oct 08 '21 at 10:02
  • Also, please, no links to screenshots of stack traces, edit the question and put the stack trace in the question formatted as code. Make sure it is the correct stack trace for the updated minimal example code that you provide so that the line numbers of the stack trace and code line up. – jewelsea Oct 08 '21 at 22:44
  • please read the referenced help page (and my comment ;) thoroughly and act accordingly (still missing: fxml, application, and the stacktrace is incomplete, afaict) – kleopatra Oct 09 '21 at 08:43
  • @kleopatra I don't know how to change this code to meet your criteria... it is my first time posting here... that is the best I could do to reduce the code... – Tamim Daudzai Oct 10 '21 at 02:15
  • which part of the referenced help page don't you understand, exactly? – kleopatra Oct 10 '21 at 09:39

1 Answers1

-1

I fixed the issue... it was a bug in Version 17 of JavaFX. reverting back to version 11 fixed the issue

  • sounds accidental - not aware of any bugs that were introduced between 11 and 17 (assuming the latter is the emergency update 17.0.1 or so ;) that might produce a stacktrace snippet as shown in the question. Without [mcve] it's hard to tell, and makes this answer rather .. well .. hope your _real_ problem doesn't hit you in future :) – kleopatra Oct 15 '21 at 09:49