cancel
Showing results for 
Search instead for 
Did you mean: 

NullPointer Exception

Former Member
0 Kudos

Hi,

When I am reading the model node element, it is throwing error since there is no value from model.

But ! I want read the model node element whether it is having value or not so based on that I can assign the value to value node. but ! it is throwing error "NullpointerException" when reading itself.

How can i resolve that ?

Regards,

Jyothi

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi jyoti,,

better you hve point out the model node size.

I am getting error in the first statement of the loop itself. since there is no value in that.

after exute this model you will get the model node size.....

//exucute model node the you will excute the this piece of code

wdThis.wdGet<component name>Contloer().excuteMethod();

int n=wdcontexxt.nodeIt_nodeAdd().size()

if(n>0){

for(int i=0;i<n;i++)

{

if(wdContext.nodeModelNode.get<Model>elementatindex(i).getName()){

String name = wdContext.nodeModelNode.get<Model>elementatindex(i).getName();

}

if (condition)

{

// fetch the data from the RFC and set in the value node as

IPrivateviewname.Icomponentnament ele = wdcontext.node<valenode>.create<Node>Element();

ele.set(name);

// and so on

wdcontext.nodevaluenode.addelement(ele);

}

}

}

Regards,

jati

Former Member
0 Kudos

Hi,

check this out in this way, maybe it will help you,

ArrayList arlSalary_HistoryTable = new ArrayList();

IPublicFcCompHistory.ISalary_HistoryElement objSalHistoryele = null;

if(nodeSizeSalHistory != 0){

for (int j=0;j<nodeSizeSalHistory;j++) {

IWDNodeElement Salary_Historylement = wdContext.nodeCompHistory_Input_Output_Salhistory().getElementAt(j);

objSalHistoryele = wdContext.nodeSalary_History().createSalary_HistoryElement();

objSalHistoryele.setAction_Date(Salary_Historylement.getAttributeValue("Action_Date").toString());

objSalHistoryele.setAction_Type(Salary_Historylement.getAttributeValue("Action_Type").toString());

objSalHistoryele.setAction_Reason(Salary_Historylement.getAttributeValue("Action_Reason").toString());

objSalHistoryele.setAnnual_Salary(Salary_Historylement.getAttributeValue("Annual_Salary").toString()+" (CAD)");

objSalHistoryele.setComp_Sal(Salary_Historylement.getAttributeValue("Comp_Sal").toString()+" (CAD)");

objSalHistoryele.setComp_Saltxt(Salary_Historylement.getAttributeValue("Comp_Saltxt").toString());

arlSalary_HistoryTable.add(objSalHistoryele);

// Bind the populated Array List to the View Var_Cash_Comp Table for Data population

wdContext.nodeSalary_History().bind(arlSalary_HistoryTable);

}

}

Cheers,

Apparao

Former Member
0 Kudos

Hi Jyothi,

After executing your model, Just check the node size .

If your modelnode is YY, then put a condition like

If(wdContext.nodeYY.size()>0)

{

}

Now your method inside this IF condition works only if you have some values in the model node. It will not get executed it if your model node does not have any value and will avoid null pointer exception.

Former Member
0 Kudos

Put a condition to check node value and if it is not null then only retrieve the value.

Hope it helps.

Former Member
0 Kudos

Hi Prasanthi,

Could you please give the systax ?

Regards,

Jyothi

pravesh_verma
Active Contributor
0 Kudos

Hi Jyothi,

I have refered to the earlier thread from your side:

I think there is some problem in the code mentioned. And as expected there will be a null pointer exception:

Please try this:


IWDNode node = wdContext.nodeModelNode();
	  int n  = 0;
	  if( node!=null && wdContext.nodeModelNode().size()>0){
		  n = wdContext.nodeModelNode.size();
	  }


	  for(int i=0;i<n;i++)
	  {

		  String name = wdContext.nodeModelNode.get<Model>elementatindex(i).getName();
		  if (condition)
		  {
//			  fetch the data from the RFC and set in the value node as

			  IPrivateviewname.Icomponentname ele = wdcontext.node<valenode>.createElement();
			  ele.set(name);
//			  and so on 
			  wdcontext.nodevaluenode.addelement(ele);
		  }
	  }

The changes which I have made is:

1) Check the model node before calculating the size.

2) Remove the invalidate function for the value node which is there. Invalidating the value node in the for loop will cause the removal of all values from value node and only the last value will persist in the node. Then if you try to access this value node with some index which is > 0 then it will give you a NULL pointer or Array out of Index exception.

I hope this helps you! Please revert back in case you need some more clarifications.

Thanks and Regards

Pravesh

Former Member
0 Kudos

Hi,

I am getting error when I am reading the model node element since there is no value in that.

How can i resolve this ?

pravesh_verma
Active Contributor
0 Kudos

Hi,

if you are getting teh error due to some missing values then you can go for explicit NULL value check. It is always recommended to do a NULL value check on the composit structures and mostly Nodes are bery complex during handling.

You should always take care of the null values which may occur in the code. Can you send me the exact line of code which is giving you the NUll pointer exception.

Also try this:


IWDNode node = wdContext.nodeModelNode();
	  int n  = 0;
	  if( node!=null && wdContext.nodeModelNode().size()>0){
		  n = wdContext.nodeModelNode.size();
	  }
 
 
	  for(int i=0;i<n;i++)
	  {
                                if(wdContext.nodeModelNode.get<Model>elementatindex(i).getName()){
                                String name = wdContext.nodeModelNode.get<Model>elementatindex(i).getName();
}
		  		  if (condition)
		  {
//			  fetch the data from the RFC and set in the value node as
 
			  IPrivateviewname.Icomponentname ele = wdcontext.node<valenode>.createElement();
			  ele.set(name);
//			  and so on 
			  wdcontext.nodevaluenode.addelement(ele);
		  }
	  }


I hope this helps! Please revert back if you have any further issue.

Thanks and Regards,

Pravesh

Former Member
0 Kudos

Hi,

I am getting error in the first statement of the loop itself. since there is no value in that.

for(int i=0;i<n;i++)

{

ERROR HERE if(wdContext.nodeModelNode.get<Model>elementatindex(i).getName()){

String name = wdContext.nodeModelNode.get<Model>elementatindex(i).getName();

}

if (condition)

{

// fetch the data from the RFC and set in the value node as

IPrivateviewname.Icomponentname ele = wdcontext.node<valenode>.createElement();

ele.set(name);

// and so on

wdcontext.nodevaluenode.addelement(ele);

}

}

Regards,

Jyothi

pravesh_verma
Active Contributor
0 Kudos

Hi,

Try this:


String name = null;
for(int i=0;i<n;i++)
{
if(wdContext.node<Model_Node_Name>()!= null && wdContext.node<Model_Node_Name>().get<Model>elementAtIndex(i).getName()){
name = wdContext.nodeModelNode.get<Model>elementatindex(i).getName();
}
if (condition)
{
// fetch the data from the RFC and set in the value node as

IPrivateviewname.Icomponentname ele = wdcontext.node<valenode>.createElement();
ele.set(name);
// and so on 
wdcontext.nodevaluenode.addelement(ele);
}
}

I hope this help!

Thanks and Regards,

Pravesh

Former Member
0 Kudos

Hi,

You are getting Null Pointer Exception, bcz there are no elements or data in the model node. You can check only if you have any elements for model nodel, it can also be a empty string.

Try a work around like -- In your onInit() method create a element for the mdoel node and bind it to the model node like:-

Iprivaterview.IABCelement ele = wdContext.nodeABC().createElement();

wdContext.nodeABC().addelement(ele);

Regards

Raghu

Former Member
0 Kudos

Hi,

Why do we need to create one more element for model node in the init() method ? . I want to check if there is any value int he model node element or not.

Can't i check the value from this ?

Regards,

Jyothi