cancel
Showing results for 
Search instead for 
Did you mean: 

Null pointer exception

Former Member
0 Kudos

Trying to create nodes dynamically. Node heirarchy is as follows

RootNode

---C100 (parent node)

-


Division (child node)

-


DivisionSet (child-child node)

All nodes are created at runtime. Except C100, all node elements are dependent non-singletons

When I execute I get a 'Null point exception' at line marked with ####, when trying to create IWDNodeElement nodeElem

Code is as follows..................................

IWDNodeInfo salesOrgs = wdContext.nodeSalesOrgs().getNodeInfo();

IWDNodeInfo salesOrg = salesOrgs.addChild("C100",null,true,true,true,false,false,true,null,null,null);

IWDNodeInfo salesOrgElement = salesOrg.addChild("Division",null,false,true,true,false,false,true,null,null,null);

salesOrg.addAttribute("defaultValue","ddic:com.sap.dictionary.string");

salesOrg.addAttribute("labelValue","ddic:com.sap.dictionary.string");

salesOrgElement.addChild("Division"+"Set",null,false,true,true,false,false,true,null,null,null);

IWDNode node = wdContext.wdGetAPI().getRootNode().getChildNode("Division",2);

IWDNodeElement nodeElem = node.createElement(); //##### - Problem here

nodeElem.setAttributeValue("defaultValue","");

nodeElem.setAttributeValue("labelValue","");

node.addElement(nodeElem);

//@@end

}

Do let me know how to recrify.

Thanks !

Sri

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Actually, the problem is one line above:

IWDNode node = wdContext.wdGetAPI().getRootNode().getChildNode("Division",2);

You are trying to get 3d element of root node and then get its direct child division. Root node has only one instance. Therefor you should use


IWDNode node100 = wdContext.wdGetAPI().getRootNode().getChildNode("C100",0);
if (node100.size > 0) /* or whatever <b>element</b> index you refer */
  IWDNode nodeDivision = node100.getChildNode("Division", 0);

VS

Former Member
0 Kudos

Kindly check if this is what you required.

You were trying to create an element of Division node and then setting the attribute. The attribute that you have created is under C100.

IWDNodeInfo salesOrgs = wdContext.nodeSalesOrgs().getNodeInfo();

IWDNodeInfo salesOrg = salesOrgs.addChild("C100",null,true,true,true,false,false,true,null,null,null);

IWDNodeInfo salesOrgElement = salesOrg.addChild("Division",null,false,true,true,false,false,true,null,null,null);

salesOrg.addAttribute("defaultValue","ddic:com.sap.dictionary.string");

salesOrg.addAttribute("labelValue","ddic:com.sap.dictionary.string");

salesOrgElement.addChild("Division"+"Set",null,false,true,true,false,false,true,null,null,null);

IWDNode node=wdContext.nodeSalesOrgs().getChildNode("C100",IWDNode.LEAD_SELECTION);

IWDNodeElement nodeElem=node.createElement();

nodeElem.setAttributeValue("defaultValue","");

nodeElem.setAttributeValue("labelValue","");

Former Member
0 Kudos

Noufal,

Think we are getting close to a resolution on this. Your code worked to perfection.

Need to tweak this code such that the attributes are created under Division node and not under C100. That is the 'defaultValue' and 'labelValue' attributes are elements of Division node. DivisionSet node is also an element of Division.

Tried some modifications to the code, but still get Null pointer exception. Code is listed below. Advise what I have coded wrongly.

IWDNodeInfo salesOrgs = wdContext.nodeSalesOrgs().getNodeInfo();

IWDNodeInfo salesOrg = salesOrgs.addChild("C100",null,true,true,true,false,false,true,null,null,null);

IWDNodeInfo salesOrgElement = salesOrg.addChild("Division",null,false,true,true,false,false,true,null,null,null);

salesOrgElement.addAttribute("defaultValue","ddic:com.sap.dictionary.string");

salesOrgElement.addAttribute("labelValue","ddic:com.sap.dictionary.string");

salesOrgElement.addChild("Division"+"Set",null,false,true,true,false,false,true,null,null,null);

IWDNode node=wdContext.getChildNode("Division",0);

IWDNodeElement nodeElem=node.createElement();

nodeElem.setAttributeValue("defaultValue","");

nodeElem.setAttributeValue("labelValue","");

Also, do I use 'bind' or 'addElement' to update 'node' with the new attribute values.

Please advise!

Sri

Former Member
0 Kudos

Guys,

Looks like I am close to resolving this issue. However, still get the message listed below.

"Node(PopulateListView.SalesOrgs.C100.Division): cannot bind or add elements because the node has no valid parent"

I have listed the moded code for your reference. Seem to run into problem when adding the element to the node (last line of code). Do let me know what needs to be done to resolve this.

IWDNodeInfo salesOrgs = wdContext.nodeSalesOrgs().getNodeInfo();

IWDNodeInfo salesOrg = salesOrgs.addChild("C100",null,true,true,true,false,false,true,null,null,null);

IWDNodeInfo salesOrgElement = salesOrg.addChild("Division",null,true,true,true,false,false,true,null,null,null);

salesOrgElement.addAttribute("defaultValue","ddic:com.sap.dictionary.string");

salesOrgElement.addChild("Division"+"Set",null,true,true,true,false,false,true,null,null,null);

IWDNode node = wdContext.wdGetAPI().getRootNode().getChildNode("SalesOrgs",0);

IWDNode node100 = node.getChildNode("C100",IWDNode.LEAD_SELECTION);

IWDNode node200 = node100.getChildNode("Division",IWDNode.LEAD_SELECTION);

IWDNodeElement nodeElem=node200.createElement();

nodeElem.setAttributeValue("defaultValue","1");

node200.addElement(nodeElem);

Thanks !

Sri

Former Member
0 Kudos

Hi,

Here is your code..

IPrivateDynAppView.ISalesOrgsElement ele=wdContext.createSalesOrgsElement();

wdContext.nodeSalesOrgs().addElement(ele);

IWDNodeInfo salesOrgs = wdContext.nodeSalesOrgs().getNodeInfo();

IWDNodeInfo salesOrg = salesOrgs.addChild("C100",null,true,true,true,false,false,true,null,null,null);

IWDNodeInfo salesOrgElement = salesOrg.addChild("Division",null,false,true,true,false,false,true,null,null,null);

salesOrgElement.addAttribute("defaultValue","ddic:com.sap.dictionary.string");

salesOrgElement.addAttribute("labelValue","ddic:com.sap.dictionary.string");

salesOrgElement.addChild("Division"+"Set",null,false,true,true,false,false,true,null,null,null);

IWDNode node=wdContext.nodeSalesOrgs().getChildNode("C100",IWDNode.LEAD_SELECTION);

IWDNodeElement elem=node.createElement();

node.addElement(elem);

IWDNode divNode=wdContext.nodeSalesOrgs().getChildNode("C100",IWDNode.LEAD_SELECTION).getChildNode("Division",0);

IWDNodeElement element=divNode.createElement();

divNode.addElement(element);

element.setAttributeValue("defaultValue","Text");

String text=wdContext.nodeSalesOrgs().getChildNode("C100",IWDNode.LEAD_SELECTION).getChildNode("Division",0).getElementAt(0).getAttributeAsText("defaultValue");

wdThis.wdGetAPI().getComponent().getMessageManager().reportSuccess(text);

Hope this is what you required...

Regards

Noufal

Message was edited by: Noufal Kareem

Former Member
0 Kudos

Pls close the topic if solved or kindly continue the discussion

Regards and wishes

Noufal

Former Member
0 Kudos

According to your context structure, "Division" is not child node of the root node.

Try this:

wdContext
  .getChildNode("C100", IWDNode.LEAD_SELECTION)
  .getChildNode("Division", 2);

Apart from this, where do you create the node elements of "C100"? You try to access the third node element.

Armin

Former Member
0 Kudos

Armin,

C100 is the child of root. Division is child of C100, and DivisionSet is child of Division.

C100 does not have any value attributes, only node element.

Sorry if the example confused you.

Do, let me know if the syntax is any different for the context structure described above.

Thanks !

Sri