cancel
Showing results for 
Search instead for 
Did you mean: 

How catch NullPointerException

Former Member
0 Kudos

Hi,

in my application I have to call a BAPI from the backend system. If I get no values from the backend I get the Internal Server Error 500. How can I avoid this message by showing my own message. I tried it with the following piece of code but it doesn't work.I call this method from my View.


	try{			
		__Nextevo__Zcm_Prv_Get_Doc_Links_Input input = new __Nextevo__Zcm_Prv_Get_Doc_Links_Input();
			
		wdContext.nodeBAPI_GLOBAL_STRUC_FROM_R3().bind(input);
					
                wdContext.nodeBAPI_GLOBAL_STRUC_FROM_R3_SORT().bind(input);
               
                input.setIm_Casid(WDWebContextAdapter.getWebContextAdapter().getRequestParameter("GUID"));

                wdContext.currentBAPI_GLOBAL_STRUC_FROM_R3Element().modelObject().execute();
		
	}catch(Exception e){
		
		msg.reportException("My own Message.............................", false);
	}	

regards,

sharam

Accepted Solutions (0)

Answers (4)

Answers (4)

former_member187658
Participant
0 Kudos

Hi Sharam

You can do the binding in your executeBapi () as well in case you are calling this method on some action or initially itself as well. You can always close the connection in the end of the method.

Secondly, after wdContext.currentBAPI_GLOBAL_STRUC_FROM_R3Element().modelObject().execute(); statement, you have to invalidate the model node's output node as well.

If you want to print your own message in case of no data, after executing the bapi, check for the size n then print ur message. If you place it in Exception case, that will be raised when the bapi execution itself throws an exception - which could be due to not passing some import parameters or could be because the bapi itself is not working roperly and throwing exception when it is run at the R/3 level itself.

So, firstly check if your bapi on dry run is running properly without any exception , and then check the parameters you are passing. Plus, add the invalidate code above.

Regards,

Anupreet

former_member189631
Active Contributor
0 Kudos

Hi Sharam,

U can do this By 2 ways ,

Way1:

Before Executing the Bapi set default values to ur Output Node elements.

This can be done By,

input.setAttriBute1(default Value);

Way2:

After The Bapi Execution Chk ur Node size.If its Null/0, Raise a Message.

Regards,

Ramganesan K.

monalisa_biswal
Contributor
0 Kudos

First of all you are getting the exception message( Internal Server Error 500) means there is some error lies in your code.Try to correct the errors first.

After execute statement you haven't invalidated output node.

Binding of node to model class instance should be done once.So it should be wrriten separately in wdDoInit.

To check whether BAPI has returned values or not :

if(wdContext.node<OutputNode>()==null||wdContext.node<OutputNode>().size==0)

{

msgMgr.reportException("Your message....",false);

}

Former Member
0 Kudos

Hi,

try

{

find the node size and try

if(i==0)

{

displaymessage

}

}

(Exception e)

{

throw new WDRuntimeException(e)

}

It might helps

thanks,

Lohi.

Message was edited by:

Lohitha M

Former Member
0 Kudos

Hi Lohi,

I try your piece of Code but I get the Internal Server Error 500 again. Now with the Message:


The initial exception that caused the request to fail, was:
   com.sap.tc.webdynpro.modelimpl.dynamicrfc.WDDynamicRFC_Fault_Exception: 

    at sun.reflect.GeneratedConstructorAccessor386.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
    at java.lang.Class.newInstance0(Class.java:308)
    at java.lang.Class.newInstance(Class.java:261)
    ... 46 more

My purpose is to show only a Web-Dynpro-Page with one Message.

Like: msg.reportException("...message.....", false);

regards,

Sharam

Former Member
0 Kudos

try{

__Nextevo__Zcm_Prv_Get_Doc_Links_Input input = new __Nextevo__Zcm_Prv_Get_Doc_Links_Input();

wdContext.nodeBAPI_GLOBAL_STRUC_FROM_R3().bind(input);

wdContext.nodeBAPI_GLOBAL_STRUC_FROM_R3_SORT().bind(input);

input.setIm_Casid(WDWebContextAdapter.getWebContextAdapter().getRequestParameter("GUID"));

wdContext.currentBAPI_GLOBAL_STRUC_FROM_R3Element().modelObject().execute();

int size = wdcontext.nodeOutput().size();

if(i==0)

{

wwdComponentApi.getMessageManager().reportsuccess("error");

}catch(Exception e){

throw new WDRuntimeException(e)

}

Thanks,

Lohi.

Former Member
0 Kudos

Hi Lohi,

sorry but it doesn't work. I couldn't catch the NullPointerException.


	try{			
		__Nextevo__Zcm_Prv_Get_Doc_Links_Input input = new __Nextevo__Zcm_Prv_Get_Doc_Links_Input();

		wdContext.nodeBAPI_GLOBAL_STRUC_FROM_R3().bind(input);

		wdContext.nodeBAPI_GLOBAL_STRUC_FROM_R3_SORT().bind(input);

		input.setIm_Casid(WDWebContextAdapter.getWebContextAdapter().getRequestParameter("GUID"));

		wdContext.currentBAPI_GLOBAL_STRUC_FROM_R3Element().modelObject().execute();

		int size = wdContext.nodeOutput().size();
		if(size == 0){
			wdComponentAPI.getMessageManager().reportSuccess("error");
		}
	
	}catch(Exception e){

		throw new WDRuntimeException(e);
	} 

Thanks,

Sharam

Former Member
0 Kudos

Hi,

try{

__Nextevo__Zcm_Prv_Get_Doc_Links_Input input = new __Nextevo__Zcm_Prv_Get_Doc_Links_Input();

// change here u instantiating one class and bind to another node.

wdContext.node__Nextevo__Zcm_Prv_Get_Doc_Links_Input().bind(input);

//wdContext.nodeBAPI_GLOBAL_STRUC_FROM_R3_SORT().bind(input);

input.setIm_Casid(WDWebContextAdapter.getWebContextAdapter().getRequestParameter("GUID"));

wdContext.current__Nextevo__Zcm_Prv_Get_Doc_Links_InputElement().modelObject().execute();

int size = wdcontext.nodeOutput().size();

if(i==0)

{

wwdComponentApi.getMessageManager().reportsuccess("error");

}catch(Exception e){

throw new WDRuntimeException(e)

}

Or therwise send ur node structure once then I will give u the code.

Thanks,

Lohi.

Former Member
0 Kudos

Hi Lohi,

thank you for your help. Hier is my Node structure:


BAPI_GLOBAL_STRUC_FROM_R3
        OUTPUT
               ET_DOC_LINKS
                     - Descr
                     - Doc_Type
                     - Doc_Type_Thumb
                     ...
                     - Url
                     - Url_Thumbnail
        -Im_Casid

regards,

Sharam