function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ankit SaxenaAnkit Saxena 

Getting Null Pointer Error -

Where am i missing, please help ?

 public static ReturnTypeClass prepareReqWrapper(ReturnTypeClass reqWrap){      
        
        ReturnTypeClass reqWrapperNew = new ReturnTypeClass();

        system.debug('reqWrap'+reqWrap);        
        try{            
            ReturnTypeClass.AR_INV_INBND_STG_ROW objInputIns = reqWrap.DataArea.AR_INV_INBND_STG_ROW != null ? reqWrap.DataArea.AR_INV_INBND_STG_ROW : new ReturnTypeClass.AR_INV_INBND_STG_ROW();
            
            reqWrapperNew.DataArea.AR_INV_INBND_STG_ROW.AMOUNT = objInputIns.AMOUNT != null ? objInputIns.AMOUNT : '0';
            }
            catch(Exception e){
            
            }
            return reqWrapperNew;
            
            
My 'ReturnTypeClass' is - 

global class ReturnTypeClass {

    public class DataArea {
        public AR_INV_INBND_STG_ROW AR_INV_INBND_STG_ROW;
    }

    public class AR_INV_INBND_STG_ROW {
        public String AMOUNT;
    }
}
           
Best Answer chosen by Ankit Saxena
<Saket><Saket>
Hi Ankit ,
 
reqWrapperNew.DataArea.AR_INV_INBND_STG_ROW.AMOUNT = objInputIns.AMOUNT != null ? objInputIns.AMOUNT : '0';
Here in the above code, I don't know how u are able to access this AR_INV_INBND_STG_ROW with the help of DataArea class because this variable is not the staitc so I think it should give u compile time error. for accessing this u have to make object first for DataArea then access I think it will work.
 

All Answers

Ankit SaxenaAnkit Saxena
**Adding - 
**Forgot to mention - 
gettting Exception Message>>>is ::Attempt to de-reference a null object
at '  reqWrapperNew.DataArea.AR_INV_INBND_STG_ROW.AMOUNT = objInputIns.AMOUNT != null ? objInputIns.AMOUNT : '0';' line----
<Saket><Saket>
Hi Ankit ,
 
reqWrapperNew.DataArea.AR_INV_INBND_STG_ROW.AMOUNT = objInputIns.AMOUNT != null ? objInputIns.AMOUNT : '0';
Here in the above code, I don't know how u are able to access this AR_INV_INBND_STG_ROW with the help of DataArea class because this variable is not the staitc so I think it should give u compile time error. for accessing this u have to make object first for DataArea then access I think it will work.
 
This was selected as the best answer