I have a URCap which generates child nodes, which I have built to have their own view/service/contribution classes, but I am struggling to get the contribution class of the child node to access variables and methods in the contribution class of the parent node. I am simply trying to write the title of the children nodes to be ChildNode1, ChildNode2 etc, depending on how many children there are. The relevant code is below
Child contribution class:
public class ChildContribution implements ProgramNodeContribution
{
private ContributionProvider<ParentNodeContribution> contributor;
//some code
public String getTitle()
{
int children = contributor.get().childrenCount();
return("ChildNode" + children);
}
//more code
}
Parent Contribution class:
public class ParentContribution implements ProgramNodeContribution
{
public int childrenCount()
{
ProgramAPI programAPI = apiProvider.getProgramAPI();
ProgramModel programModel = programAPI.getProgramModel();
model.set("children", programModel.getRootTreeNode(this).getChildren().size());
return programModel.getRootTreeNode(this).getChildren().size();
}
}
However whenever I run the code and generate a new child node, it tells my that getTitle has a null pointer exception error.
I know the childrenCount () method runs as intended because i can access it and print its results to JLabels in the ParentNodeView class.
Can anyone offer a solution?
Thanks in advance.