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
NikunjVadiNikunjVadi 

System.NullPointerException: Argument cannot be null.

I am getting null value in my object but dont know why .

mail class:

public class ReportVariables{
        HomeEvaluation__c obj = new HomeEvaluation__c();     
        public Decimal MaxHealth =0 ;
       

        public Decimal Healthandcomfort(Integer Hea,Integer Maxvalue,Decimal CurrentMax){
        Id pageid=ApexPages.currentPage().getParameters().get('id');
        obj.Id=pageid;
      
 If(Hea==0)
        {
       
        MaxHealth = obj.Max_Health_and_comfort__c;
        obj.Max_Health_and_comfort__c= MaxHealth;
        update obj;
        return MaxHealth;
        }
        else{
        MaxHealth = Maxvalue + obj.Max_Health_and_comfort__c ;
        obj.Max_Health_and_comfort__c = MaxHealth;
        update obj;
        return MaxHealth;
       
        }

       }


Calling this class on pagereference but i am getting null value eventhough i am assiging some value before calling the class. 
page reference
pageid=ApexPages.currentPage().getParameters().get('id');
         obj.Id=pageid;
         obj.Ventilation_Ducting__c = Ducting;
         obj.Ducting_Notes__c=DuctingNotes;
         obj.Max_Health_and_comfort__c=0;
         update obj;
         Repobj.Healthandcomfort(Ducting,6,0);
         DuctingReportvalue = 2 * Ducting;

On the second page reference i need to used old value saved in the record. getting same error that time also.:

pageid=ApexPages.currentPage().getParameters().get('id');
         obj.Id=pageid;
         obj.Ventilation_Filters_Photo_air_condit__c = Filters;
         obj.Filter_Notes__c=FilterNotes;
         update obj;
         FilterMax = obj.Max_Health_and_comfort__c;
         Repobj.Healthandcomfort(Filters,9,FilterMax);
         FiltersReportvalue = 3 * Filters;


please help me out 
Deepak Kumar ShyoranDeepak Kumar Shyoran
It seems that on line 
Repobj.Healthandcomfort(Ducting,6,0);

you are facing a null with Ducting and the method is expecting a integer value try replacing it with some integer number if Ducting is null.

NikunjVadiNikunjVadi
Ducting is not null , i replaced it with an integer, i am getting null value in obj.Max_Health_and_comfort__c .
Deepak Kumar ShyoranDeepak Kumar Shyoran
Then you can put a validation to check null value and use that to avoid this exception.
NikunjVadiNikunjVadi
That value cant be null.

When i go to first page to second value will be 6 , but if i am tring to recall it by using obj.Max_Health_and_comfort__c  i am getting null,

so there wont be null value at any time because even at start i am giving 0 value. 
I dont know what i am doing wrong , not able to understand why i am not getting value that is in the record
Deepak Kumar ShyoranDeepak Kumar Shyoran
As you mentioned you are switching between first page to second so have you created a wizard means redirecting to another page from first with the help of Controller "Pagereference" . If not then please create a wizard for two pages as if you are not in a wizard then while moving to another page first page controller state disappear/vanished and you will not be able to get values of variable related to first controller.