You need to sign in to do that
Don't have an account?
rornelas
question about null pointer error
Hi Everyone,
I have this code below. Can anybody tell me why this code throws the Null Pointer exception?
I have this code below. Can anybody tell me why this code throws the Null Pointer exception?
try { List<String> nameList; Account a; String s = a.Name; nameList.add( s ); } catch ( ListException le ) { System.debug('List Exception'); } catch ( NullPointerException npe ) { System.debug('NullPointer Exception'); } catch ( Exception e ) { System.debug('Generic Exception'); }
Please find the code here .
try
{
List<String> nameList= new List<String>();
Account a= new Account(Name ='Test');
String s = a.Name;
nameList.add( s );
}
catch ( ListException le )
{
System.debug('List Exception');
}
catch ( NullPointerException npe )
{
System.debug('NullPointer Exception');
}
catch ( Exception e )
{
System.debug('Generic Exception');
}
All Answers
Please find the code here .
try
{
List<String> nameList= new List<String>();
Account a= new Account(Name ='Test');
String s = a.Name;
nameList.add( s );
}
catch ( ListException le )
{
System.debug('List Exception');
}
catch ( NullPointerException npe )
{
System.debug('NullPointer Exception');
}
catch ( Exception e )
{
System.debug('Generic Exception');
}
like:
If(a.id !=null )
{
String s = a.Name
}
Let me know if it helps
Thanks