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?