cancel
Showing results for 
Search instead for 
Did you mean: 

null pointer error

Former Member
0 Kudos

Hi I got a null pointer.

ihave the following code:

//@@begin executeY_Tf_Start_Process_Input()

Y_Tf_Start_Process_Input inputPS = new Y_Tf_Start_Process_Input();

inputPS.setScenario_Key(wdContext.currentYtf_MainprocessPLElement().getScenariokey());

inputPS.setPernr(wdContext.currentEmployee_ListELElement().getPernr());

inputPS.setCountry(wdContext.currentCountriesCLElement().getLand1());

inputPS.setMainprocesskey(wdContext.currentYtf_MainprocessPLElement().getMainprocesskey());

inputPS.setReason(wdContext.currentReasonsPRElement().getReason());

wdContext.nodeY_Tf_Start_Process_Input().bind(inputPS);

try

{

wdContext.currentY_Tf_Start_Process_InputElement().modelObject().execute();

wdContext.nodeOutputPS().invalidate();

}

catch (Exception ex)

{

ex.printStackTrace();

}

//@@end

}

_____________

error message:

java.lang.NullPointerException

at com.shell.teamflow.wd.processstart.ProcessStart_Cust.executeY_Tf_Start_Process_Input(ProcessStart_Cust.java:220)

at com.shell.teamflow.wd.processstart.wdp.InternalProcessStart_Cust.executeY_Tf_Start_Process_Input(InternalProcessStart_Cust.java:395)

at com.shell.teamflow.wd.processstart.StartProcessView.onActionStartProcess(StartProcessView.java:177)

at com.shell.teamflow.wd.processstart.wdp.InternalStartProcessView.wdInvokeEventHandler(InternalStartProcessView.java:432)

at com.sap.tc.webdynpro.progmodel.generation.DelegatingView.invokeEventHandler(DelegatingView.java:87)

at com.sap.tc.webdynpro.progmodel.controller.Action.fire(Action.java:67)

at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.handleAction(WebDynproMainTask.java:101)

at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.handleActionEvent(WebDynproMainTask.java:304)

at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.execute(WebDynproMainTask.java:649)

at com.sap.tc.webdynpro.clientserver.cal.AbstractClient.executeTasks(AbstractClient.java:59)

at com.sap.tc.webdynpro.clientserver.cal.ClientManager.doProcessing(ClientManager.java:248)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doWebDynproProcessing(DispatcherServlet.java:154)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doContent(DispatcherServlet.java:116)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doPost(DispatcherServlet.java:55)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

try this

try

{

if(wdContext.currentReasonsPRElement().getReason()!=null)

inputPS.setReason(wdContext.currentReasonsPRElement().getReason());

}

catch(NullPointerException e)

{

inputPS.setReason("");

}

Regards,

Ajay

Former Member
0 Kudos

Ajay, this solved the problem. Thanks

Answers (8)

Answers (8)

Former Member
0 Kudos

Hi

Doesn't this help you resolve your problem?

try

{

wdContext.currentReasonsPRElement().getReason()!=null)

inputPS.setReason(wdContext.currentReasonsPRElement().getReason());

}

catch(NullPointerException e)

{

inputPS.setReason("");

}

Regards,

Ajay

Former Member
0 Kudos

Ajay

i get an invalid expression statement with

wdContext.currentReasonsPRElement().getReason()!=null)

Former Member
0 Kudos

Hi

Create other node (You can Change the cardinality here 1..n)and bind the bapi value to the node and bind it to the view.

You unable to check the null with cardinality 0..n when the value is null.

Kind Regards

Mukesh

Former Member
0 Kudos

hi i am not creating any value node directly from view i trying to pass value to model node

is it possible or not

Former Member
0 Kudos

Hi

I think you should check if you are getting the Reasons populated in the ReasonsPR node.If you are, then check if Reason is mandatory parameter.If it is then you have to pass the correct value to this parameter.

Anyway could you please post the stacktrace?

Regards,

Ajay

Former Member
0 Kudos

if the reasons are in the back-end. they fill my table...

stacktrace?

I am rookie in java

Former Member
0 Kudos

Hi

wdContext.currentReasonsPRElement().getReason() itself is giving Null pointer Exception.

Hence use the try catch block as per my previous post and the check.

Regards,

Ajay

suresh_krishnamoorthy
Active Contributor
0 Kudos

Still ur reponse from ReasonsPR is null...

try once like this:

if(wdContext.currentReasonsPRElement().getReason()!=null)

{

//tmp your getting null value check whether you mapped to response(ReasonsPR) and is getting value from bapi?

String tmp = "";

tmp = wdContext.currentReasonsPRElement().getReason();

if(tmp != "")

inputPS.setReason(tmp);

else

inputPS.setReason("");

}

else

inputPS.setReason("");

Regards

Suresh

Former Member
0 Kudos

still nullpointer

___________________________

cardinality is o.n

Message was edited by: Eoin Cronan

Former Member
0 Kudos

Hi

Try using

try

{

wdContext.currentReasonsPRElement().getReason()!=null)

inputPS.setReason(wdContext.currentReasonsPRElement().getReason());

}

catch(NullPointerException e)

{

inputPS.setReason("");

}

Regards,

Ajay

Former Member
0 Kudos

Hi

Are you sure that the element for the node ReasonsPR exists?If not then make sure that you have one by setting its cardinality to 1..n or by creating it.If you already have one then use try catch block for that code.

In catch block set the reason to "".

Regards,

Ajay

Former Member
0 Kudos

cardinality is 1..n. it is directly from bapi.

what do you mean: with In catch block set the reason to "".

suresh_krishnamoorthy
Active Contributor
0 Kudos

Hi,

if(wdContext.currentReasonsPRElement().getReason()!=null)

{

//tmp your getting null value check whether you mapped to response(ReasonsPR) and is getting value from bapi?

String tmp = wdContext.currentReasonsPRElement().getReason();

if(tmp != null)

inputPS.setReason(tmp);

else

inputPS.setReason("");

}

else

inputPS.setReason("");

Regards

Suresh

Former Member
0 Kudos

hi,

1.is the node ReasonsPR from BAPI?

2.try{

if((wdContext.currentReasonsPRElement().getReason()!=null){

inputPS.setReason(wdContext.currentReasonsPRElement().getReason());

}else{

inputPS.setReason("");

}

}catch(Exception e){

inputPS.setReason("");

}

// do the Other

Kind Regards

Mukesh

Former Member
0 Kudos

java.lang.NullPointerException

at com.shell.teamflow.wd.processstart.ProcessStart_Cust.executeY_Tf_Start_Process_Input(ProcessStart_Cust.java:221)

at com.shell.teamflow.wd.processstart.wdp.InternalProcessStart_Cust.executeY_Tf_Start_Process_Input(InternalProcessStart_Cust.java:395)

at com.shell.teamflow.wd.processstart.StartProcessView.onActionStartProcess(StartProcessView.java:177)

at com.shell.teamflow.wd.processstart.wdp.InternalStartProcessView.wdInvokeEventHandler(InternalStartProcessView.java:432)

at com.sap.tc.webdynpro.progmodel.generation.DelegatingView.invokeEventHandler(DelegatingView.java:87)

at com.sap.tc.webdynpro.progmodel.controller.Action.fire(Action.java:67)

at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.handleAction(WebDynproMainTask.java:101)

at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.handleActionEvent(WebDynproMainTask.java:304)

at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.execute(WebDynproMainTask.java:649)

at com.sap.tc.webdynpro.clientserver.cal.AbstractClient.executeTasks(AbstractClient.java:59)

at com.sap.tc.webdynpro.clientserver.cal.ClientManager.doProcessing(ClientManager.java:248)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doWebDynproProcessing(DispatcherServlet.java:154)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doContent(DispatcherServlet.java:116)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doPost(DispatcherServlet.java:55)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

___________________________________________________

Y_Tf_Start_Process_Input inputPS = new Y_Tf_Start_Process_Input();

inputPS.setScenario_Key(wdContext.currentYtf_MainprocessPLElement().getScenariokey());

inputPS.setPernr(wdContext.currentEmployee_ListELElement().getPernr());

inputPS.setCountry(wdContext.currentCountriesCLElement().getLand1());

inputPS.setMainprocesskey(wdContext.currentYtf_MainprocessPLElement().getMainprocesskey());

if(wdContext.currentReasonsPRElement().getReason()!=null)

{

//tmp your getting null value check whether you mapped to response(ReasonsPR) and is getting value from bapi?

String tmp = wdContext.currentReasonsPRElement().getReason();

if(tmp != null)

inputPS.setReason(tmp);

else

inputPS.setReason("");

}

else

inputPS.setReason("");

// if(wdContext.currentReasonsPRElement().getReason()!=null)

// inputPS.setReason("");

// else

// inputPS.setReason(wdContext.currentReasonsPRElement().getReason());

wdContext.nodeY_Tf_Start_Process_Input().bind(inputPS);

try

{

wdContext.currentY_Tf_Start_Process_InputElement().modelObject().execute();

wdContext.nodeOutputPS().invalidate();

}

catch (Exception ex)

{

ex.printStackTrace();

}

Former Member
0 Kudos

yes it is from the bapi

if i use your code i get unresolved type and other messages. what do i need to replace?

Former Member
0 Kudos

Hi,

Try this

Create other node (You can Change the cardinality here 1..n)and bind the bapi value to the node and bind it to the view.

You unable to check the null with cardinality 0..n when the value is null

//for binding the value from Bapi to dropdown

IPrivate<ViewName>.I<DropName>Node node = wdContext.node<DropName>();

int len=wdContext.node<BAPIList>().size();

for(int l=0;l<len;l++) {

String

returndata=String.valueOf(((IPrivate<viewname>.I<BAPIList>Element)(wdContext.node<BAPIList>(

).getElementAt(l))).get<Parameter>());

IPrivate<ViewName>.I<DropName>Element element =

wdContext.create<DropName>Element();

element.set<Param>(returndata);

node.addElement(element);

}

Kind Regards

Mukesh

Former Member
0 Kudos

Hi

What is the line no. 221 in your ProcessStart_Cust.java.

It is causing this exception.Could you please post it?

Regards,

Ajay

Former Member
0 Kudos

node property is 0.1

______________________________

Y_Tf_Start_Process_Input inputPS = new Y_Tf_Start_Process_Input();

inputPS.setScenario_Key(wdContext.currentYtf_MainprocessPLElement().getScenariokey());

inputPS.setPernr(wdContext.currentEmployee_ListELElement().getPernr());

inputPS.setCountry(wdContext.currentCountriesCLElement().getLand1());

inputPS.setMainprocesskey(wdContext.currentYtf_MainprocessPLElement().getMainprocesskey());

if

(wdContext.currentReasonsPRElement().getReason()!=null)

inputPS.setReason

<221>(wdContext.currentReasonsPRElement().getReason());

else

inputPS.setReason("");

wdContext.nodeY_Tf_Start_Process_Input().bind(inputPS);

try

{

wdContext.currentY_Tf_Start_Process_InputElement().modelObject().execute();

wdContext.nodeOutputPS().invalidate();

}

catch (Exception ex)

{

ex.printStackTrace();

}

Message was edited by: Eoin Cronan

Former Member
0 Kudos

Hi

The error occurd at line number 220.

And check that element is not null which you have bind to that line.

Kind Regards

Mukesh

Former Member
0 Kudos

your code is not saying if one of the attributes is null that this is also ok

Former Member
0 Kudos

How can i do this?

Which code should I make then if one of these is null that he still needs go to bapi

Former Member
0 Kudos

Hi

Check all the input is null then bind it to the BAPI Input

like

Y_Tf_Start_Process_Input inputPS = new Y_Tf_Start_Process_Input();

if(wdContext.currentYtf_MainprocessPLElement().getScenariokey()!=null){

inputPS.setScenario_Key(wdContext.currentYtf_MainprocessPLElement().getScenariokey());

}

if(wdContext.currentEmployee_ListELElement().getPernr()!=null){

inputPS.setPernr(wdContext.currentEmployee_ListELElement().getPernr());

}

if(wdContext.currentCountriesCLElement().getLand1()!=null){

inputPS.setCountry(wdContext.currentCountriesCLElement().getLand1());

}

if(wdContext.currentYtf_MainprocessPLElement().getMainprocesskey()!=null){

inputPS.setMainprocesskey(wdContext.currentYtf_MainprocessPLElement().getMainprocesskey());

}

if(wdContext.currentReasonsPRElement().getReason()!=null){

inputPS.setReason(wdContext.currentReasonsPRElement().getReason());

}

//do the execute

Kind Regards

Mukesh.

Former Member
0 Kudos

Bsome input can be null. which code should i put with it then

suresh_krishnamoorthy
Active Contributor
0 Kudos

Hi,

try like this..

if(wdContext.currentReasonsPRElement().getReason()!=null)

inputPS.setReason(wdContext.currentReasonsPRElement().getReason());

else

inputPS.setReason("");

Regards

Suresh

Former Member
0 Kudos

Again I null pointer with this code

java.lang.NullPointerException

at com.shell.teamflow.wd.processstart.ProcessStart_Cust.executeY_Tf_Start_Process_Input(ProcessStart_Cust.java:221)

at com.shell.teamflow.wd.processstart.wdp.InternalProcessStart_Cust.executeY_Tf_Start_Process_Input(InternalProcessStart_Cust.java:395)

at com.shell.teamflow.wd.processstart.StartProcessView.onActionStartProcess(StartProcessView.java:177)

at com.shell.teamflow.wd.processstart.wdp.InternalStartProcessView.wdInvokeEventHandler(InternalStartProcessView.java:432)

at com.sap.tc.webdynpro.progmodel.generation.DelegatingView.invokeEventHandler(DelegatingView.java:87)

at com.sap.tc.webdynpro.progmodel.controller.Action.fire(Action.java:67)

at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.handleAction(WebDynproMainTask.java:101)

at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.handleActionEvent(WebDynproMainTask.java:304)

at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.execute(WebDynproMainTask.java:649)

at com.sap.tc.webdynpro.clientserver.cal.AbstractClient.executeTasks(AbstractClient.java:59)

at com.sap.tc.webdynpro.clientserver.cal.ClientManager.doProcessing(ClientManager.java:248)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doWebDynproProcessing(DispatcherServlet.java:154)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doContent(DispatcherServlet.java:116)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doPost(DispatcherServlet.java:55)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)

Former Member
0 Kudos

Hi

If some can be empty means check the selection property of the node at line 221.The node should be have selection property 0..1 or 1..1.

Kind Regards

Mukesh

Former Member
0 Kudos

Hi

It is occurring because you are accessing current<Node>Element of some node which actually does not exist.

The error is in line 220 of your ProcessStart_Cust.java.

Check if the node you are accessing in this line actually has the element.If not the create one or set the cardinality to 1..n.

Regards,

Ajay