# Communication between different ProgramNodeContribution Classes

**URL:** https://forum.universal-robots.com/t/communication-between-different-programnodecontribution-classes/3148
**Category:** Java
**Created:** [November 21, 2018, 11:04am UTC](https://forum.universal-robots.com/t/communication-between-different-programnodecontribution-classes/3148 "2018-11-21T11:04:48Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![sam.verity-hilton](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/sam.verity-hilton/32/6046_2.png) [@sam.verity-hilton](https://forum.universal-robots.com/u/sam.verity-hilton)
#### Post date: [November 21, 2018, 11:04am UTC](https://forum.universal-robots.com/t/communication-between-different-programnodecontribution-classes/3148/1 "2018-11-21T11:04:48Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![jbm](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/jbm/32/614_2.png) [@jbm](https://forum.universal-robots.com/u/jbm)
#### Post date: [November 21, 2018, 1:00pm UTC](https://forum.universal-robots.com/t/communication-between-different-programnodecontribution-classes/3148/2 "2018-11-21T13:00:44Z")

</div>

Generally speaking, the parent node can access the child nodes.  
But the child nodes cannot get or modify parents or siblings.

In order for the parent node to get the child nodes, you should use the `ProgramNodeVisitor` to visit any URCap program node child.  
Then, each of these children should implement a URCap proprietary API.  
And if the parent `canGetAs()` on these child URCap nodes, they are an instance of the desired child node type.  
The nodes can then be configured using the methods provided by this proprietary API.

An example of this implementation can be found in this example:

> [@URCap Sample: URCap CustomAPI](https://forum.universal-robots.com/t/sample-urcap-customapi/3022):
>
> URCap CustomAPI Description of functionality: This example demonstrated the usage of the URCap CustomAPI interface. Allowing a parent node to configure the configuration of its child node. In this example, this is covered by allowing the parent node to define the color of the child node. What topics are covered: Proprietary API, Custom API, parent node, child node, interfaces [Find it on Github!](https://github.com/BomMadsen/URCap-CustomAPI) Requirements: URCaps API 1.3 (Swing)

Btw, I am a bit in doubt of the usage of your `ContributionProvider` in the child node contribution.  
The purpose of the ContributionProvider, is to provide access to an active contribution from the View-class.  
And the usage displayed here, is probably not supported.
