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
Akshata ShahAkshata Shah 

error: Attempt to de-reference a null object at EmployeeOnLeave.add(l);

Vf page
 
<apex:pageBlock rendered="{!(EmployeeOnLeave.size>0)}">
                        <apex:outputPanel id="EmployeeOnLeave">
                            <apex:pageBlockTable value="{!EmployeeOnLeave}" var="l" id="EmpOnLeave" title="Employee on Leave today">
                                <apex:column headerValue="Name" value="{!l.Resource__r.Name}" /> 
                                <apex:column headerValue="To Date" value="{!l.To_Date__c}" />
                                <apex:column headerValue="Type" value="{!l.Type__c}" />
                                <apex:column headerValue="Status" value="{!l.Decision__c}" />
                            </apex:pageBlockTable>
                        </apex:outputPanel>
                    </apex:pageBlock>

controller
 
public List<Leave__c> EmployeeOnLeave{set;get;}
public void  getEmployeeLeave(){
        
        date dt=date.today();
        system.debug(dt);
        List<Leave__c> AllLeaveList=new List<Leave__c>();
        
        AllLeaveList=[Select Resource__r.Name,From_Date__c,To_Date__c,Type__c,Decision__c From Leave__c where Decision__c=:'Approved'];
        
        system.debug(AllLeaveList);
        if(AllLeaveList.size()>0){
            for(Leave__c l:AllLeaveList){
                system.debug(l);
                if(dt>=l.From_Date__c && dt<=l.To_date__c){
                    EmployeeOnLeave.add(l);
                }
                system.debug(EmployeeOnLeave);
            }
        }
    }
Error is at  EmployeeOnLeave.add(l);
please help me
Regards,
Akshata​​
Best Answer chosen by Akshata Shah
David Zhu 🔥David Zhu 🔥
You may need to instantiate employeeOnleave in the method.

public void getEmployeeLeave(){
EmployeeOnLeave = new List<Leave__c>();