I have a lookup relationship.
If I just do the following query it works fine:
Sobject c = [select field__r.fieldchild__c from custom_obj where Id = :someId];
system.debug('c:' + c);
However with the following I get an error:
Sobject c = [select field__r.fieldchild__c from custom_obj where Id = :someId];
String c2 = (String) r.getSobject('field__r').get('fieldchild__c');
Error message:
FATAL_ERROR System.NullPointerException: Attempt to de-reference a null object