4

I am getting above error when I run my module in browser as: 192.168.0.106/magento-2/module1/index/index

Below is my Controller code:

<?php
namespace Company1\Module1\Controller\Index;
class Index extends \Magento\Framework\App\Action\Action
{
    protected $resultPageFactory;
    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Framework\View\Result\PageFactory $resultPageFactory
    )
    {
        ## parent::__construct($context);
        $this->resultPageFactory = $resultPageFactory;
        parent::__construct($context);
    }
    public function execute()
    {
        return $this->resultPageFactory->create();
    }
}

Here is the routes.xml:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/App/etc/routes.xsd">
    <router id="standard">
        <route id="module1" frontName="module1">
            <module name="Company1_Module1"/>
        </route>
    </router>
</config>

Module.xml

<?xml version="1.0"?>
<!--<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
  <module name="Company1_Module1" schema_version="1.0.0" setup_version="1.0.0"/>
</config>

And Block file:

<?php

namespace Company1\Module1\Block;

class Module1 extends \Magento\Framework\View\Element\Template
{
    public function _prepareLayout()
    {
        return parent::_prepareLayout();
    }
}

Layout file:

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd" layout="3columns">
    <head>
        <title>Module1 Text !!!</title>
    </head>
  <body>
    <referenceContainer name="content">
      <block class="Company1\Module1\Block\Module1" name="module1" template="Company1_Module1::default.phtml"></block>
    </referenceContainer>
  </body>
</page>
3
  • you should check var/log/system.log.
    – xanka
    Commented Nov 30, 2015 at 7:21
  • Are you create registration.php n custom module of you ?
    – LinoPham
    Commented Nov 30, 2015 at 7:28
  • Yes it's already there.
    – Vicky Dev
    Commented Nov 30, 2015 at 7:43

4 Answers 4

4

This error shows when there is error in your module layout file please once double cross check that file and try to comment some of its code and debug with trial and error you should get the solution.

2
  • I have updated the question to include layout file as well, this layout is in same format which is used in one of my other modules too, but the one here isn't working. Please check and let me know what could be the issue ?
    – Vicky Dev
    Commented Nov 30, 2015 at 10:26
  • In Magento 2.0.0 CE there are many changes are done. You have to check for your module all .xml file. XML file header defination are changed. You have to check all xml file xsi:noNamespaceSchemaLocation value from latest version core module and set that value in xml file. xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd". You have to set new value for above location in your module all xml file.Your issue are solved after change xml value. Also registation.php and composer.json file must need in module root.
    – Rushvi
    Commented Nov 30, 2015 at 10:39
1

There is only one reason for this error, that your default.phtml file is not there or not there in templates directory (make sure templates folder is with (s)).

1

I had this problem as well. In my situation I changed some lowercase characters to uppercase characters and Git doesn't take these as a commit in a case-insensitive system. Some pointers to fix this:

  • The first thing: create 2 commits for case-changes: exampleClass -> rename to foo_exampleClass -> commit -> rename to ExampleClass -> commit. This way, you have the correct name in your Git repository.
  • Make sure you're changes are also reflected in any layout files where you references the class. For example: <block class="Foo\Bar\Block\exampleBlock"/> needs to be changed to <block class="Foo\Bar\Block\ExampleBlock"/>.
  • Another gotcha: if you used the class in dependency injection or factory generators, change these as well in your constructor call: \Foo\Bar\Model\blaFactory $blaFactory -> \Foo\Bar\Model\BlaFactory $blaFactory.
  • Other occasions, like extending classes or instantiating with the object manager for example are of course a no-brainer, but the above points can be easily overseen (especially the layout and DI stuff).

Hope this helps someone.

0

For me this was caused by my Block class re-defining a method in a parent class with a signature that did not match the parent class's signature. You may want to check system.log or support_report.log for errors being logged regarding your block class

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.