You need to sign in to do that
Don't have an account?
bonny mankotia
Show Anonymous Error
Hello Guys.I have the following code its show an error Line: 16, Column: 1System.NullPointerException: Attempt to de-reference a null object.I want to know the reason behind this error.Is this not proper way to declare and initiliaze object like this way please help me.
public with sharing class MapExampleTwo
{
public void display()
{
account acc4;
acc4.name = 'Peter';
account acc5;
acc5.name = 'corey';
account acc = new account();
acc.name = 'bonny';
account acc1 = new account();
acc1.name = 'bonsy';
account acc3 = new account(name = 'bonson');
map<integer,account>map1 = new map<integer,account>{0 => acc,1 => acc1,2 => acc3};
system.debug('The first index is' + map1.get(0));
system.debug('====='+map1.keyset());
system.debug('===='+map1.values());
}
}
public with sharing class MapExampleTwo
{
public void display()
{
account acc4;
acc4.name = 'Peter';
account acc5;
acc5.name = 'corey';
account acc = new account();
acc.name = 'bonny';
account acc1 = new account();
acc1.name = 'bonsy';
account acc3 = new account(name = 'bonson');
map<integer,account>map1 = new map<integer,account>{0 => acc,1 => acc1,2 => acc3};
system.debug('The first index is' + map1.get(0));
system.debug('====='+map1.keyset());
system.debug('===='+map1.values());
}
}
PLease try below code.