Notice: Trying to get property of non-object - Symfony 3
<p>I've continued my learning with symfony. But with some errors, which in this moment. I cant resolve.
I'm using Symfony3 and Postman, I'm creating the UserController, and I have an error with editAction.
When I send a token (authorization) and the user data (json) through POST method. This is the error message
<strong>Notice: Trying to get property of non-object</strong></p>

<p>500 Internal Server Error - ContextErrorException</p>

<p><a href="http://i.stack.imgur.com/9dHAC.png" rel="nofollow">http://localhost:8080/curso-fullstack/symfony/web/app_dev.php/user/edit</a></p>

<p>This is my UserController code</p>

<pre><code>    &lt;?php

namespace AppBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\HttpFoundation\JsonResponse;
use BackendBundle\Entity\User;

class UserController extends Controller {

    public function newAction(Request $request) {
        $helpers = $this-&gt;get("app.helpers");

        $json = $request-&gt;get("json", null);
        $params = json_decode($json);
        $data = array(
            "status" =&gt; "error",
            "code" =&gt; 400,
            "msg" =&gt; "User not created"
        );

        if ($json != null) {
            $createdAt = new \Datetime("now");
            $image = null;
            $role = "user";

            $email = (isset($params-&gt;email)) ? $params-&gt;email : null;
            $name = (isset($params-&gt;name) &amp;&amp; ctype_alpha($params-&gt;name)) ? $params-&gt;name : null;
            $surname = (isset($params-&gt;surname) &amp;&amp; ctype_alpha($params-&gt;surname)) ? $params-&gt;surname : null;
            $password = (isset($params-&gt;password)) ? $params-&gt;password : null;

            $emailConstraint = new Assert\Email();
            $emailConstraint-&gt;message = "This email is not valid";
            $validate_email = $this-&gt;get("validator")-&gt;validate($email, $emailConstraint);

            if ($email != null &amp;&amp; count($validate_email) == 0 &amp;&amp;
                    $password != null &amp;&amp; $name != null &amp;&amp; $surname != null
            ) {
                $user = new User();
                $user-&gt;setCreatedAt($createdAt);
                $user-&gt;setImage($image);
                $user-&gt;setRole($role);
                $user-&gt;setEmail($email);
                $user-&gt;setName($name);
                $user-&gt;setSurname($surname);

                //Cifrar la Password
                $pwd = hash('sha256', $password);
                $user-&gt;setPassword($pwd);

                $em = $this-&gt;getDoctrine()-&gt;getManager();
                $isset_user = $em-&gt;getRepository("BackendBundle:User")-&gt;findBy(
                        array(
                            "email" =&gt; $email
                ));
                if (count($isset_user) == 0) {
                    $em-&gt;persist($user);
                    $em-&gt;flush();

                    $data["status"] = 'success';
                    $data["code"] = 200;
                    $data["msg"] = 'New user created !!';
                } else {
                    $data = array(
                        "status" =&gt; "error",
                        "code" =&gt; 400,
                        "msg" =&gt; "User not created, duplicated"
                    );
                }
            }
        }
        return $helpers-&gt;json($data);
    }

    public function editAction(Request $request) {
        $helpers = $this-&gt;get("app.helpers");

        $hash = $request-&gt;get("authorization", null);
        $authCheck = $helpers-&gt;authCheck($hash);

        if ($authCheck == true) {

            $identity = $helpers-&gt;authCheck($hash, true);

            $em = $this-&gt;getDoctrine()-&gt;getManager();
            $user = $em-&gt;getRepository("BackendBundle:User")-&gt;findOneBy(array(
                    "id" =&gt; $identity-&gt;sub
            ));

            $json = $request-&gt;get("json", null);
            $params = json_decode($json);

            $data = array(
                "status" =&gt; "error",
                "code" =&gt; 400,
                "msg" =&gt; "User not updated"
            );

            if ($json != null) {
                $createdAt = new \Datetime("now");
                $image = null;
                $role = "user";

                $email = (isset($params-&gt;email)) ? $params-&gt;email : null;
                $name = (isset($params-&gt;name) &amp;&amp; ctype_alpha($params-&gt;name)) ? $params-&gt;name : null;
                $surname = (isset($params-&gt;surname) &amp;&amp; ctype_alpha($params-&gt;surname)) ? $params-&gt;surname : null;
                $password = (isset($params-&gt;password)) ? $params-&gt;password : null;

                $emailContraint = new Assert\Email();
                $emailContraint-&gt;message = "This email is not valid !!";
                $validate_email = $this-&gt;get("validator")-&gt;validate($email, $emailContraint);

                if ($email != null &amp;&amp; count($validate_email) == 0 &amp;&amp;
                     $name != null &amp;&amp; $surname != null
                ) {
                    $user-&gt;setCreatedAt($createdAt);
                    //$user-&gt;setImage($image);
                    $user-&gt;setRole($role);
                    $user-&gt;setEmail($email);
                    $user-&gt;setName($name);
                    $user-&gt;setSurname($surname);

                    if($password != null &amp;&amp; !empty($password)){
                        //Cifrar la password
                        $pwd = hash('sha256', $password);
                        $user-&gt;setPassword($pwd);
                    }

                    $em = $this-&gt;getDoctrine()-&gt;getManager();
                    $isset_user = $em-&gt;getRepository("BackendBundle:User")-&gt;findBy(
                            array(
                                "email" =&gt; $email
                    ));

                    if (count($isset_user) == 0 || $identity-&gt;email == $email) {
                        $em-&gt;persist($user);
                        $em-&gt;flush();

                        $data["status"] = 'success';
                        $data["code"] = 200;
                        $data["msg"] = 'User updated !!';
                    } else {
                        $data = array(
                            "status" =&gt; "error",
                            "code" =&gt; 400,
                            "msg" =&gt; "User not updated, duplicated!!"
                        );
                    }
                }
            } else {
                $data = array(
                    "status" =&gt; "error",
                    "code" =&gt; 400,
                    "msg" =&gt; "Authorization not valid"
                );
            }
        }

        return $helpers-&gt;json($data);
    }
//    public function uploadImageAction(Request $request) {
//        $helpers = $this-&gt;get("app.helpers");
//
//        $hash = $request-&gt;get("authorization", null);
//        $authCheck = $helpers-&gt;authCheck($hash);
//
//        if ($authCheck) {
//            $identity = $helpers-&gt;authCheck($hash, true);
//
//            $em = $this-&gt;getDoctrine()-&gt;getManager();
//            $user = $em-&gt;getRepository("BackendBundle:User")-&gt;findOneBy(array(
//                "id" =&gt; $identity-&gt;sub
//            ));
//
//            //Upload File
//            $file = $request-&gt;files-&gt;get("image");
//            if (!empty($file) &amp;&amp; $file != null) {
//                $ext = $file-&gt;guessExtension();
//                $file_name = time() . "." . $ext;
//                $file-&gt;move("uploads/users", $file_name);
//
//                $user-&gt;setImage($file_name);
//                $em-&gt;persist($user);
//                $em-&gt;flush();
//
//                $data = array(
//                    "status" =&gt; "success",
//                    "code" =&gt; 200,
//                    "msg" =&gt; "Image for user uploaded success !!"
//                );
//            } else {
//                $data = array(
//                    "status" =&gt; "error",
//                    "code" =&gt; 400,
//                    "msg" =&gt; "Image not uploaded"
//                );
//            }
//        } else {
//            $data = array(
//                "status" =&gt; "error",
//                "code" =&gt; 400,
//                "msg" =&gt; "Authorization not valid"
//            );
//        }
//        return $helpers-&gt;json($data);
//    }
}
</code></pre>

<p>I hope you can give me a hand</p>

<p><em>Here is stack trace</em></p>

<pre><code>Stack Trace
in src\AppBundle\Controller\UserController.php at line 89   -

            $em = $this-&gt;getDoctrine()-&gt;getManager();
            $user = $em-&gt;getRepository("BackendBundle:User")-&gt;findOneBy(array(
                    "id" =&gt; $identity-&gt;sub
            ));

            $json = $request-&gt;get("json", null);
at ErrorHandler -&gt;handleError ('8', 'Trying to get property of non-object', 'C:\xampp\htdocs\curso-fullstack\symfony\src\AppBundle\Controller\UserController.php', '89', array('request' =&gt; object(Request), 'helpers' =&gt; object(Helpers), 'hash' =&gt; 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOjcsImVtYWlsIjoiYXlhbmV6QG1haWwuY2wiLCJuYW1lIjoiQWxlamFuZHJvIiwic3VybmFtZSI6InlhbmV6IiwicGFzc3dvcmQiOiI3MThlMzk3ODUxNmQzODc5MjRkOTE5ODBhN2UyMWFmMmY0MzRkZTQ0NTczMTk1MWE2NTg1YmRhMmVhY2VmMDQ2IiwiaW1hZ2UiOm51bGwsImlhdCI6MTQ3NDg4NTczMywiZXhwIjoxNDc1NDkwNTMzfQ.1Lvbm4op7Xvz9oJ3kerPwnapqj-AbPuHqkEjGlFNgc4', 'authCheck' =&gt; true, 'identity' =&gt; true, 'em' =&gt; object(EntityManager))) 
in src\AppBundle\Controller\UserController.php at line 89   + 
at UserController -&gt;editAction (object(Request)) 
at call_user_func_array (array(object(UserController), 'editAction'), array(object(Request))) 
in vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php at line 144   + 
at HttpKernel -&gt;handleRaw (object(Request), '1') 
in vendor\symfony\symfony\src\Symfony\Component\HttpKernel\HttpKernel.php at line 64   + 
at HttpKernel -&gt;handle (object(Request), '1', true) 
in vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php at line 169   + 
at Kernel -&gt;handle (object(Request)) 
in web\app_dev.php at line 30   + 
Logs   - 1 error
INFO - Matched route "user_edit". 
INFO - Populated the TokenStorage with an anonymous Token. 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::configure". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\DumpListener::configure". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ValidateRequestListener::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\FragmentListener::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\TranslatorListener::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\Security\Http\Firewall::onKernelRequest". 
DEBUG - Notified event "kernel.controller" to listener "Symfony\Bundle\FrameworkBundle\DataCollector\RouterDataCollector::onKernelController". 
DEBUG - Notified event "kernel.controller" to listener "Symfony\Component\HttpKernel\DataCollector\RequestDataCollector::onKernelController". 
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ControllerListener::onKernelController". 
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ParamConverterListener::onKernelController". 
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\HttpCacheListener::onKernelController". 
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\SecurityListener::onKernelController". 
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener::onKernelController". 
CRITICAL - Uncaught PHP Exception Symfony\Component\Debug\Exception\ContextErrorException: "Notice: Trying to get property of non-object" at C:\xampp\htdocs\curso-fullstack\symfony\src\AppBundle\Controller\UserController.php line 89 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::configure". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\DumpListener::configure". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ValidateRequestListener::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\FragmentListener::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\TranslatorListener::onKernelRequest". 
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\Security\Http\Firewall::onKernelRequest". 
DEBUG - Notified event "kernel.controller" to listener "Symfony\Bundle\FrameworkBundle\DataCollector\RouterDataCollector::onKernelController". 
DEBUG - Notified event "kernel.controller" to listener "Symfony\Component\HttpKernel\DataCollector\RequestDataCollector::onKernelController". 
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ControllerListener::onKernelController". 
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ParamConverterListener::onKernelController". 
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\HttpCacheListener::onKernelController". 
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\SecurityListener::onKernelController". 
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener::onKernelController". 
Stack Trace (Plain Text)   +
</code></pre>

<p>Thanks</p>