title: "Module (User) could not be initialized" : Exception in Zend Framework 2
body: <p>I have downloaded the skeleton application of Zend Framework 2. Then I am creating a module named "User".</p>
  
  <p>Folder structure;</p>
  
  <pre><code>Module
    .....
    User
     config
        module.config.php
     src
        Controller
          UserController.php
        Model
          User.php
          UserTable.php
        Form
        Module.php
     view
        index.phtml
        ...
  </code></pre>
  
  <p>I have added 'User' in application's modules.config.php</p>
  
  <pre><code>return [
    'Zend\Form',
    'Zend\Db',
    'Zend\Router',
    'Zend\Validator',
    'Application',
    'User',
  ];
  </code></pre>
  
  <p>My Module.php code is as follow;</p>
  
  <pre><code>&lt;?php
   namespace User;
  
   use Zend\ModuleManager\Feature\ConfigProviderInterface;
  
  class Module implements ConfigProviderInterface
  {
  public function getConfig()
  {
      return include __DIR__ . '/../config/module.config.php';
  }
  
  public function getServiceConfig()
  {
      return [
          'factories' =&gt; [
  
              Model\UserTable::class =&gt; function($container) {
                  $tableGateway = $container-&gt;get(Model\UserTableGateway::class);
                  return new Model\UserTable($tableGateway);
              },
  
              Model\UserTableGateway::class =&gt; function ($container) {
                  $dbAdapter = $container-&gt;get(AdapterInterface::class);
                  $resultSetPrototype = new ResultSet();
                  $resultSetPrototype-&gt;setArrayObjectPrototype(new Model\User());
                  return new TableGateway('user', $dbAdapter, null, $resultSetPrototype);
              },
          ],
      ];
  }
  
  public function getControllerConfig()
  {
      return [
          'factories' =&gt; [
              Controller\UserController::class =&gt; function($container) {
                  return new Controller\UserController(
                      $container-&gt;get(Model\UserTable::class)
                  );
              },
          ],
      ];
  }
  }
  </code></pre>
  
  <p>Inside composer.json</p>
  
  <pre><code>"autoload": {
      "psr-4": {
          "Application\\": "module/Application/src/",
          "User\\": "module/User/src/",
      }
  },
  </code></pre>
  
  <p>But I am getting the error "Module (User) could not be initialized". I am new to Zend Framework. I think something is wrong in Module.php. I tried all answers in <strong>stackoverflow</strong>. Most of them indicates <strong>namespace</strong> issue. But I think I have given it correct.
  Can you please point out the issue please, if more code needed please mention.</p>