cancel
Showing results for 
Search instead for 
Did you mean: 

problem mutliply two BIGDecimal variable

Former Member
0 Kudos

hi

i have written the below code , and all the elements

iam getting from the RFC are returning me of type

BigDecimal and i need to calculate the price*numberofnight

he is staying in the hotel , so i have multiplied in the

below way

BigDecimal nightNumber=wdContext.nodeIpsitd().currentIpsitdElement().getMnits();

BigDecimal pitchPrice=wdContext.nodeOpprcid().currentOpprcidElement().getPthpr();

BigDecimal pitchFee=pitchPrice.multiply(nightNumber);

java.lang.NullPointerException

at java.math.BigDecimal.multiply(BigDecimal.java:412)

at uk.co.caravanclub.BookingDetails.onActionGetPrice(BookingDetails.java:303)

at uk.co.caravanclub.wdp.InternalBookingDetails.wdInvokeEventHandler(InternalBookingDetails.java:520)

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

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

iam getting this error ,

can any one help me out?

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

k

Former Member
0 Kudos

Hi Kishore..

Jus initilize all the BigDecimal var's like

BigDecimal var = new BigDecimal("0.00");

BigDecimal var1 = new BigDecimal("0.00");

do this for all the bigdecimal var's ur using ..so u can aviod Null pointer exception.

regards

Rajesh

Former Member
0 Kudos

You get NullPointerException when your object variables are not instantiated, its a good practice that when ever you use such variables first check for the NullPointerException before using them.

Sample Code:

BigDecimal nightNumber = wdContext.nodeIpsitd().currentIpsitdElement().getMnits();
BigDecimal pitchPrice = wdContext.nodeOpprcid().currentOpprcidElement().getPthpr();

BigDecimal pitchFee = new BigDecimal("0"); //Initialization here will avoid NullPointerException

if (nightNumber != null && pitchPrice != null)
    pitchFee = pitchPrice.multiply(nightNumber);

Regards,

Jawed Ali

Former Member
0 Kudos

Hi,

Check whether the values coming from backend with null

and proceed to multiply if they are not null

Regards

LN

Former Member
0 Kudos

Hi,

Have you debugged to check whether nightNumber is null or not?

Regards,

Satyajit.

Former Member
0 Kudos

Hi Kishore,

Did you try putting the debug messages to verify what values are you getting from the backend?

In webdynpro we can print messages on the screen with Web Dynpro Message Manager API , as below :


BigDecimal nightNumber=wdContext.nodeIpsitd().currentIpsitdElement().getMnits();
weComponentAPI.wdGetMessageManger.reportSuccess("night Number" + nightNumber);

BigDecimal pitchPrice=wdContext.nodeOpprcid().currentOpprcidElement().getPthpr();
weComponentAPI.wdGetMessageManger.reportSuccess("pitchPrice" + pitchPrice);

//BigDecimal pitchFee=pitchPrice.multiply(nightNumber); 

Please run this code and verify on the screen what values are displaying from the back end?

Thanks

Krishna