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
Sree SalesforceSree Salesforce 

I got a small error like System.NullPointerException: Attempt to de-reference a null object Error is in expression '{!save}' in component <apex:commandButton> in page actionstatus: Class.storedata.save: line 17, column 1

<apex:page controller="storedata" showHeader="false">
<apex:form >
  <apex:pageBlock title="account details">
  <apex:pageBlockButtons >
   <apex:commandButton value="save" action="{!save}" status="acctid"/>
  
  </apex:pageBlockButtons>
   <apex:pageblockSection >
    <apex:inputField value="{!acc.name}"/>
    <apex:inputField value="{!acc.type}"/>
    <apex:inputField value="{!acc.phone}"/>
   </apex:pageblockSection>
   <apex:pageBlockSection >
    <apex:inputField value="{!acc.rating}"/>
   
   </apex:pageBlockSection>
  </apex:pageBlock>
</apex:form>
</apex:page>

public class storedata {

    public account getAccount() {
        return acc;
    }


    public account acc { get; set; }
   
     public storedata()
     {
      list<account> acc=[select id,name,type,phone,rating from account where id=:apexpages.currentpage().getparameters().get('id')];
      
        }

    public PageReference save() {
        update acc;
        return null;
       
}
}
Best Answer chosen by Sree Salesforce
AshwaniAshwani
Try it:

public class storedata {

    public account getAccount() {
        return acc;
    }


     public account acc { get; set; }
   
     public storedata() {
       list<account> acc=[select id,name,type,phone,rating from account where id=:apexpages.currentpage().getparameters().get('id')];
      this.acc = new Account();
      
     }

    public PageReference save() {
        update acc;
        return null;
       
    }
}