1

I have an Accordion pane that is dynamically populated with TitledPanes. Each TitlePane needs to hold a child AnchorPane that will display relevant information for that object. The child AnchorPane is held in a separate FXML file and needs to be loaded when the TitledPane is expanded.

This is the controller I'm trying to use:

public class PeopleViewController {

DataSource data;

@FXML
private Accordion accordion;
@FXML
private AnchorPane detailAnchor;
@FXML
private TableView<HashMap<String, String>> dataTable;
@FXML
private TableColumn<HashMap<String, String>,String> propertyiesColumn;
@FXML
private TableColumn<HashMap<String, String>,String> detailsColumn;

public ScheduleViewController(){
    data = new DataSource();
}


@FXML
private void initialize() {
    ObservableList<String> nameList = FXCollections.observableArrayList(dataSource.getNames()); 
    for(String name:nameList){
        accordion.getPanes().add(buildTitledPane(name));
    }
    accordion.setVisible(true);
}

private TitledPane buildTitledPane(final String text){
    final TitledPane tp = new TitledPane();
    tp.setText(text);
    tp.expandedProperty().addListener(new ChangeListener<Boolean>() {
        @Override
        public void changed(
                ObservableValue<? extends Boolean> observable,
                Boolean oldValue, Boolean newValue) {
            if(tp.isExpanded()){
            getPersonData(tp);
            }
        }
    });
    return tp;
}


@FXML
private void getPersonData(TitledPane tp){
    try {
        detailAnchor = FXMLLoader.load(getClass().getResource("PersonDetail.fxml"));
    } catch (IOException e) {
        e.printStackTrace();
    }
    //Will add data to the table here
    tp.setContent(detailAnchor);
}

However getPersonData() throws a java.lang.reflect.InvocationTargetException... Caused by: java.lang.NullPointerException. I'm obviously not loading the file correctly. What am I doing wrong?

spacitron
  • 2,095
  • 7
  • 30
  • 39
  • Please include the complete error message+stack trace. Be sure to mark the relevant lines from the in stack trace in your code. We may need the PersonDetail.fxml file and the controller class of PersonDetail.fxml, if existent (but only, if the stack trace mentions it). – fabian Jan 07 '14 at 23:54
  • may be this work `AnchorPane page = (AnchorPane) fxmlLoader.load(url.openStream()); detailPane.getChildren().clear();///name of pane where you want to put the fxml detailPane.getChildren().add(page);` – Anshul Parashar Jan 10 '14 at 06:14

0 Answers0