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
NaveenReddyNaveenReddy 

System.NullPointerException: Attempt to de-reference a null object error

<apex:page standardController="Account" extensions="testPicklist">
      <apex:tabPanel >
      <apex:tab label="accounts" name="accounts" id="tab1" >
      
      <apex:pageblock >
                   <apex:pageBlockSection title="">
                   <apex:pageBlockTable value="{!lstAccounts}" var="acc"  >
                   <!--<apex:column value="{!acc.CreatedBy}"/>-->
                   <apex:column value="{!acc.AccountNumber}"/>
                   
                   </apex:pageBlockTable>
                   </apex:pageBlockSection>
             </apex:pageblock>
             </apex:tab>
      <apex:tab label="contact" name="contacts" id="tab2"/>
             </apex:tabPanel>
             
             
         
 </apex:page>

 

public class testPicklist
         {

    public final Account acct;
    List<Account> lstAccounts{get; set;}
    public testPicklist(ApexPages.StandardController controller)
           {
            acct=(Account)controller.getRecord();
           }
           public List<Account> getlstAccounts()
           {
           lstAccounts.add([select name,id from Account]);
           return lstAccounts;
           }
    
       }

 

 

while itry to execute this code Im getting System.NullPointerException: Attempt to de-reference a null object  error error .

 

Can  any one please help..urgent

 

 

georggeorg

Hi,

 

Please use the following controller, there  was few issues in the controller you have written.

 

1.lstAccounts list was not  instantiated and you were trying to add elements into that list

2.You were using list add methd, in which you can pass only a single element, but the query was returning a list of elements

3. You were using accountNumber in the page , but that was not queried in the soql.

 

I have corrected the above issues, pleas let me know if there are any isuses.

Also visit the url : http://learnsfdc.blogspot.in/2013/01/data-to-sets-in-apex-small-mistake-that.html

 

public class testPicklist
{

public final Account acct;
List<Account> lstAccounts{get; set;}
public testPicklist(ApexPages.StandardController controller)
{
acct=(Account)controller.getRecord();
lstAccounts = new List<Account>();
}
public List<Account> getlstAccounts()
{
lstAccounts.addAll([select name,id,AccountNumber from Account]);
return lstAccounts;
}

}

NaveenReddyNaveenReddy

thaks a lot  georg its working fine now......I wl post u more for my queries...