Print hasOne data

[ Warning (2) ](javascript:void(0);): Attempt to read property “mobile” on null [in /srv/canteen1/app/templates/Users/index.php, line 29]
error comes on list users
index.php is

<?= $this->Paginator->sort('id') ?> <?= $this->Paginator->sort('username') ?> <?= $this->Paginator->sort('email') ?> Mobile <?= $this->Paginator->sort('created') ?> <?= $this->Paginator->sort('modified') ?> <?= __('Actions') ?> <?php foreach ($users as $user): ?> <?= $this->Number->format($user->id) ?> <?= h($user->username) ?> <?= h($user->email) ?> <?= h($user->contact->mobile) ?>> <?= h($user->created) ?> <?= h($user->modified) ?> <?= $this->Html->link(__('View'), ['action' => 'view', $user->id]) ?> <?= $this->Html->link(__('Edit'), ['action' => 'edit', $user->id]) ?> <?= $this->Form->postLink(__('Delete'), ['action' => 'delete', $user->id], ['confirm' => __('Are you sure you want to delete # {0}?', $user->id)]) ?>

user.php in model is

protected $_accessible = [
‘username’ => true,
‘email’ => true,
‘password’ => true,
‘created’ => true,
‘modified’ => true,
‘contact’ => true,
‘skills’ => true,
];

usertable.php in model is

 */
public function initialize(array $config): void
{
    parent::initialize($config);

    $this->setTable('users');
    $this->setDisplayField('id');
    $this->setPrimaryKey('id');

    $this->addBehavior('Timestamp');
    $this->hasOne('Contacts');/* 
    $this->hasMany('Contacts', [
        'foreignKey' => 'user_id',
    ]); */
    $this->hasMany('Skills');
}

/**

userscontroller.php is

public function index()
{
$users = $this->paginate($this->Users);

    $this->set(compact('users'));
}

/**
 * View method
 *
 * @param string|null $id User id.
 * @return \Cake\Http\Response|null|void Renders view
 * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
 */
public function view($id = null)
{
    $user = $this->Users->get($id, ['contain' => ['Contacts']]);

    $this->set(compact('user'));
    
}

found the problem
contain is to added in index function rather than view function