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
Vigneshwaran LoganathanVigneshwaran Loganathan 

Error : Attempt to de-reference a null object

Hi,

I am trying to get all the selected records from data table using Onchange function, but got the error, where am i making mistake?

VF:
<apex:dataTable value="{!wrapPriceList}" var="pdWrap" columnswidth="50px,50px" cellpadding="4" border="1" align="center" id="reRenderPbId">
                 <apex:column >
                           <apex:facet name="header">
                             <apex:inputCheckbox >
                                <apex:actionSupport event="onclick" action="{!getselected1}" onsubmit="selectAllCheckboxes(this,'inputId')" rerender="inputId"/>
                             </apex:inputCheckbox> 
                           </apex:facet>
                        <apex:inputCheckbox value="{!pdWrap.selected}" id="inputId">
                            <apex:actionSupport event="onclick" action="{!GetSelected1}" rerender="false"/>
                       </apex:inputCheckbox>          
                 </apex:column>   
                  <apex:column headerValue="Operating Model"><apex:outputtext value="{!pdWrap.pds.Name}" /></apex:column> 
    </apex:dataTable>

Controller :
public class QuoteController{
public List<Price_details__c> prc;
public List<Price_details__c> selectedprd=new List<Price_details__c>();
public list<price_details__c> getselected1;
public Boolean rendcart{get;set;}
public price_details__c price{get;set;}
public Price_details__c SearchCriteria{get;set;}
public List<wrapPrice> wrapPriceList{get;set;}
public List<Price_details__c> wrapPriceList2{get;set;}
public opportunity opp{get;set;}
public String cid = ApexPages.currentPage().getParameters().get('id');
public QuoteController(ApexPages.StandardController controller) 
         { 
           SearchCriteria = new Price_details__c();
           prc= new list<Price_details__c>();
           region = false;
           typef = false;          
         } 

public void filterapp()
{
       godis=true;
       wrapPriceList = new List<wrapPrice>();   
      if(SearchCriteria.Operating_Model__c!=null && Quantity!=null && SearchCriteria.Region__c!=null && typeSelected==null)
      {
          for(Price_Details__c pd: [SELECT Id,Operating_Model__c,Buying_Price__c,Type__c,MSRP__c, Name FROM Price_details__c WHERE Operating_Model__c =: SearchCriteria.Operating_Model__c and QuantityStart__c<=:Quantity 
            and QuantityEnd__c>=:Quantity and region__c=:SearchCriteria.region__c ])
            {
            wrapPriceList.add(new wrapPrice(pd));
            }
      }  
     }    
    system.debug('>>>wrapPriceList'+wrapPriceList);  
 }
 
 
 public pagereference getSelected1() 
{
    system.debug('>>>wraps'+wrapPriceList); // here i got all records 
    for(wrapPrice wrapx:wrapPriceList)
    if(wrapx !=null && wrapx.selected==true )
    {
      system.debug('>>>wraps'+wrapx); // here i got the purticular selected record
      wrapPriceList2.add(wrapx.pds);  // Error at this line 
    }
    return null;  
}
public class wrapPrice {
        public Price_Details__c pds {get; set;}
        public Boolean selected {get; set;}
 
        public wrapPrice(Price_Details__c pd) {
            pds = pd;
            selected = false;
        }
}
}

Thanks in advance.
Best Answer chosen by Vigneshwaran Loganathan
Himanshu ParasharHimanshu Parashar
Hi,

you are getting this error because you have missed initialization of this list, add following line in your constructor after line 14

 List<Price_details__c> wrapPriceList2  = new  List<Price_details__c>();

Thanks,
Himanshu

All Answers

Himanshu ParasharHimanshu Parashar
Hi,

you are getting this error because you have missed initialization of this list, add following line in your constructor after line 14

 List<Price_details__c> wrapPriceList2  = new  List<Price_details__c>();

Thanks,
Himanshu
This was selected as the best answer
Vigneshwaran LoganathanVigneshwaran Loganathan
Thank you so much Himanshu :))