Fatal error: Call to a member function getId() on null in doctrine
<p>I have a error saying that,  </p>

<pre><code>Fatal error: Call to a member function getId() on null.
</code></pre>

<p>but how can i check the element, here is my code </p>

<pre><code>$infoArray['groupId'] = $info-&gt;getId();
$infoArray['name'] = $info-&gt;getName();
$infoArray['addressLine1'] = $info-&gt;getAddressLine1();
$infoArray['addressLine2'] = $info-&gt;getAddressLine2();
$infoArray['isActive'] = $info-&gt;getActive();
$infoArray['countryId'] = $info-&gt;getCountry()-&gt;getId(); //Here is my error line
$infoArray['countryName'] = $info-&gt;getCountry()-&gt;getName();
$infoArray['stateId'] = $info-&gt;getState()-&gt;getId();
$infoArray['stateName'] = $info-&gt;getState()-&gt;getName();
$infoArray['cityId'] = $info-&gt;getCity()-&gt;getId();
$infoArray['cityName'] = $info-&gt;getCity()-&gt;getName();
$infoArray['areaId'] = $info-&gt;getArea()-&gt;getId();
$infoArray['areaName'] = $info-&gt;getArea()-&gt;getName();
$infoArray['zipcode'] = $info-&gt;getZipcode();
</code></pre>