+ Start a Discussion
sreedharp286sreedharp286 

How to solve System.NullPointerException: Attempt to de-reference a null object ?

 

 

public  class calculator1{

public integer num1{get;set;}
public integer num2{get;set;}
public integer num3{get;set;}

 
 
public void add(){
num3=num1+num2;
//EmailConformation1 E=new EmailConformation1();
//E.sendMail();
}
}

 

Best Answer chosen by Admin (Salesforce Developers) 
hisalesforcehisalesforce

public void add(){

 

if(num1==null)

         num1=0;

if(num2==null)

            num2=0;
num3=num1+num2;
//EmailConformation1 E=new EmailConformation1();
//E.sendMail();
}

All Answers

hisalesforcehisalesforce

public void add(){

 

if(num1==null)

         num1=0;

if(num2==null)

            num2=0;
num3=num1+num2;
//EmailConformation1 E=new EmailConformation1();
//E.sendMail();
}

This was selected as the best answer
sreedharp286sreedharp286
now resolved Thanks boss
jgaiottojgaiotto

You may wanna do it in the property itself, as stated in my response to your double post : http://boards.developerforce.com/t5/Apex-Code-Development/How-to-solve-System-NullPointerException-Attempt-to-de-reference/td-p/666184

 

More important, your problem is solved ;)