You need to sign in to do that
Don't have an account?
Harry Moeung
Attempt to de-reference a null object Error
Hello Devs,
I am getting a
'System.NullPointerException: Attempt to de-reference a null object' error when attempting to add values to a list of an object. I am not quite sure what is causing this error but I don't believe I'm passing a null value into the list. I need to add items to the oandaExchangeRateList invocable variable so I can pass that into an Apex Flow.
//This is the wrapper class. Rmoved a lot of code for readability.
public with sharing class OandaExchangeRatesCalloutsWrapperV1 {
public class methodOutputs{
@InvocableVariable
public List<OandaExchangeRate__c> oandaExchangeRateList;
}
}
//This is the debug code that gives me the Null Pointer Exception Error
OandaExchangeRate__c oandaExchangeRate = new OandaExchangeRate__c();
oandaExchangeRate.Base_Currency__c = 'USD';
oandaExchangeRate.Quote_Currency__c = 'USD';
oandaExchangeRate.Average_Exchange_Rate__c = 1.0;
OandaExchangeRatesCalloutsWrapperV1.methodOutputs wrapper = new OandaExchangeRatesCalloutsWrapperV1.methodOutputs();
wrapper.oandaExchangeRateList.add(oandaExchangeRate);
I am getting a
'System.NullPointerException: Attempt to de-reference a null object' error when attempting to add values to a list of an object. I am not quite sure what is causing this error but I don't believe I'm passing a null value into the list. I need to add items to the oandaExchangeRateList invocable variable so I can pass that into an Apex Flow.
//This is the wrapper class. Rmoved a lot of code for readability.
public with sharing class OandaExchangeRatesCalloutsWrapperV1 {
public class methodOutputs{
@InvocableVariable
public List<OandaExchangeRate__c> oandaExchangeRateList;
}
}
//This is the debug code that gives me the Null Pointer Exception Error
OandaExchangeRate__c oandaExchangeRate = new OandaExchangeRate__c();
oandaExchangeRate.Base_Currency__c = 'USD';
oandaExchangeRate.Quote_Currency__c = 'USD';
oandaExchangeRate.Average_Exchange_Rate__c = 1.0;
OandaExchangeRatesCalloutsWrapperV1.methodOutputs wrapper = new OandaExchangeRatesCalloutsWrapperV1.methodOutputs();
wrapper.oandaExchangeRateList.add(oandaExchangeRate);
Please change here I hope this help
You have to initiate the oandaExchangeRateList like below:
Thanks,
Maharajan.C
Thanks for the help. Both solutions worked!