+ Start a Discussion

Getting Null Pointer Exception

I am trying to add months to a date field and add that value to the List<Date>. I am getting null pointer exception

Apex Code
public class stndReduceExcel {
   public Contingency__c stndReduce{get;set;}
    public List<Date> bill{get;set;}
    ApexPages.StandardController controller;

    public stndReduceExcel(ApexPages.StandardController con){
        controller = con;
        stndReduce = [Select name, Account__c, BILLING_BEGINS_DATE__c,  Num_to_Bill__c   from Contingency__c where id = :System.currentPagereference().getParameters().get('id')];
          Date newbill =  stndReduce.BILLING_BEGINS_DATE__c;
        for(Integer i = 1; i <= stndReduce.Num_to_Bill__c ; i++){
            newBill = newBill.addMonths(i);

I am getting Null Pointer exceptbill.add(newBill). I used system debug statement shows the correct value.

Cant understand how to fix this. 
Any help would be aapreciated!
Best Answer chosen by SF_Monkey
Tad Aalgaard 3Tad Aalgaard 3
You need the following line at the beginning of your stndReduceExcel method in order to instantiate the bill List.
bill = new List<Date>();