Can't find the cause of this error I am working through a Drupal 8 module building exercise from YouTube and I am not able to figure out what is causing an error. The relevant page loads and displays the form but I get the following error message:

Notice: Trying to get property of non-object in Drupal\rsvplist\Form\RSVPForm->buildForm() (line 29 of modules/custom/rsvplist/src/Form/RSVPForm.php).

Drupal\rsvplist\Form\RSVPForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 518)
Drupal\Core\Form\FormBuilder->retrieveForm('rsvplist_email_form', Object) (Line: 275)
Drupal\Core\Form\FormBuilder->buildForm('rsvplist_email_form', Object) (Line: 93)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber{closure}() (Line: 582)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 38)
Drupal\webprofiler\StackMiddleware\WebprofilerMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 693)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

The code for the form is here:

&lt;?php 
/**
  *@file
  *Contains \Drupal\rsvplist\Form\RSVPForm
  */
namespace Drupal\rsvplist\Form;

use Drupal\Core\Database\Database;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;

/**
 *Provides an RSVP email form
 */

class RSVPForm extends FormBase {
  /**
   * (@inheritdoc)
   */
  public function getFormId() {
      return 'rsvplist_email_form';
  }

  /**
   * (@inheritdoc)
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
      $node = \Drupal::routeMatch()-&gt;getParameter('node');
      $nid = $node-&gt;nid-&gt;value;
      $form['email'] = array(
          '#title' =&gt; t('email address'),
          '#type' =&gt; 'textfield',
          '#size' =&gt; 25,
          '#description' =&gt; t("We will send updates to the email address you provide"),
          '#required' =&gt; TRUE,
      );
      $form['submit'] = array(
          '#type' =&gt; 'submit',
          '#value' =&gt; t('RSVP'),         
      );
      $form['nid'] = array(
          '#type' =&gt; 'hidden',
          '#value' =&gt; $nid,
      );
      return $form;
  }
  public function submitForm(array &amp;$form, FormStateInterface $form_state) {
      drupal_set_message(t('The form is working'));
  }
}



The Drupal version is 8.6.15. PHP Version is 7.0.15 Can anyone spot an error I am missing?
Line line 29:

$nid = $node->nid->value;

Try this solution:

$node-&gt;id();


Very useful thing "Drupal 8 Entity API cheat sheet": https://www.metaltoad.com/blog/drupal-8-entity-api-cheat-sheet