cancel
Showing results for 
Search instead for 
Did you mean: 

REG : Null Pointer Exception for RFC values

Former Member
0 Kudos

Hi All,

I am facing peculiar erro in code.I need to check the null entries in SAP server then it should be replaced by space and if not null then should be replaced by the value in backend.But it is throwing null pointer exception

I am using equalsignore case(null) and trim for space.

I am not getting why its is throwing null pointer exception.Kindly advise

Regards,

Anupama

Accepted Solutions (1)

Accepted Solutions (1)

former_member185086
Active Contributor
0 Kudos

Hi

Please understand there is difference between null and having one space

1. null is the reserved constant used in Java to represent a void reference i.e a pointer to nothing. Internally it is just a binary 0, but in the high level Java language, it is a magic constant, quite distinct from zero, that internally could have any representation.

2.The String trim() method returns a copy of the string, with leading and trailing whitespace omitted.

3. Check for space i.e (if (abc ! == " ")) . (I need to check the null entries in SAP server then it should be replaced by space and if not null then should be replaced by the value in backend.But it is throwing null pointer exception)

if it true then populate the actual values

Best Regards

Satish Kumar

Former Member
0 Kudos

How about catching the Null pointer exception and writing a code to change the null entries with what you want say space?

Try it out.

Regards

Avik

Former Member
0 Kudos

i have craeted object fr Catch(Exception e) and if abc == null then setabc(" ");

else i am setting the value what user will enter in frontend

former_member185086
Active Contributor
0 Kudos

Hi

Use

String f = null ;
if(f!==null)
Wdcomponent.getMessageManager.ReportException ("this will cause null pointer exception  "+ f.length());

Better to give it any Constant like

priveate static final String NULL_CHECK  = "DEL_VAL12";

rather than space ,at the time of chceking see if it has DEL_VAL12 if true then put the actual data else let it be there.

Best Regards

Satish Kumar

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi All,

Thanks for replies.I got the solution as I have done this by checking the node size greater than zero,its now showing in a correct way what it was supposed to display.Instead of taking field of RFC i took whole node as if size of node is zero then it will defintely wont be having any fields and no feld is having value as zero so the way of valdiation itself was going wrong.

If you have to check the backend valeu is null then take the node's size as validation parameter.

Regards,

Anupama

Former Member
0 Kudos

Hi Anupama,

Obviously, when we are picking some value from RFC Model then, the very first thing that we need to do is to check if the Node Itself is not null. Then check if the size of the node is not null......then element of the node at a given index is not null....then the attribute value is not null and then finally attribute values when trimmed to get rid of leading and trailing spaces is not equal to empty string. This way, would wont get any exception at all. Hope it helps you when you encounter similar exceptions in the future.

Regards,

Tushar Sinha

Former Member
0 Kudos

Hi,

If you use equalsIgnoreCase to compare null value you will get null pointer exception; because this method compares with another string.

Try to use (== null) and check.

Regards,

Manjunath

Former Member
0 Kudos

Hi Manjunath,

thanks for replying but i too checked with == but still no changes..

Anything else we can do.Moreover i tried != null but still error comes

Regards,

Anupama