0

Error in magento 2.0.11 while accessing custom block

Invalid block type: Tomrain\Appcustomizer\Block\Customizepage
#0 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/View/Layout/Generator/Block.php(237): Magento\Framework\View\Layout\Generator\Block->getBlockInstance('Tomrain\\Appcust...', Array)
#1 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/View/Layout/Generator/Block.php(215): Magento\Framework\View\Layout\Generator\Block->createBlock('Tomrain\\Appcust...', 'customizepage', Array)
#2 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/View/Layout/Generator/Block.php(124): Magento\Framework\View\Layout\Generator\Block->generateBlock(Object(Magento\Framework\View\Layout\ScheduledStructure), Object(Magento\Framework\View\Layout\Data\Structure), 'customizepage')
#3 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/View/Layout/GeneratorPool.php(86): Magento\Framework\View\Layout\Generator\Block->process(Object(Magento\Framework\View\Layout\Reader\Context), Object(Magento\Framework\View\Layout\Generator\Context))
#4 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/View/Layout.php(327): Magento\Framework\View\Layout\GeneratorPool->process(Object(Magento\Framework\View\Layout\Reader\Context), Object(Magento\Framework\View\Layout\Generator\Context))
#5 /var/www/html/appcustomizer-tshirt-M2/var/generation/Magento/Framework/View/Layout/Interceptor.php(89): Magento\Framework\View\Layout->generateElements()
#6 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/View/Layout/Builder.php(129): Magento\Framework\View\Layout\Interceptor->generateElements()
#7 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/View/Page/Builder.php(55): Magento\Framework\View\Layout\Builder->generateLayoutBlocks()
#8 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/View/Layout/Builder.php(65): Magento\Framework\View\Page\Builder->generateLayoutBlocks()
#9 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/View/Page/Config.php(187): Magento\Framework\View\Layout\Builder->build()
#10 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/View/Page/Config.php(197): Magento\Framework\View\Page\Config->build()
#11 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/App/View.php(170): Magento\Framework\View\Page\Config->publicBuild()
#12 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/App/View.php(114): Magento\Framework\App\View->loadLayoutUpdates()
#13 /var/www/html/appcustomizer-tshirt-M2/app/code/Tomrain/Appcustomizer/Controller/Customize/index.php(20): Magento\Framework\App\View->loadLayout()
#14 /var/www/html/appcustomizer-tshirt-M2/var/generation/Tomrain/Appcustomizer/Controller/Customize/index/Interceptor.php(24): Tomrain\Appcustomizer\Controller\Customize\Index->execute()
#15 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/App/Action/Action.php(102): Tomrain\Appcustomizer\Controller\Customize\index\Interceptor->execute()
#16 [internal function]: Magento\Framework\App\Action\Action->dispatch(Object(Magento\Framework\App\Request\Http))
#17 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/Interception/Interceptor.php(74): call_user_func_array(Array, Array)
#18 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/Interception/Chain/Chain.php(70): Tomrain\Appcustomizer\Controller\Customize\index\Interceptor->___callParent('dispatch', Array)
#19 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Tomrain\\Appcust...', 'dispatch', Object(Tomrain\Appcustomizer\Controller\Customize\index\Interceptor), Array, 'designLoader')
#20 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/App/Action/Plugin/Design.php(39): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
#21 [internal function]: Magento\Framework\App\Action\Plugin\Design->aroundDispatch(Object(Tomrain\Appcustomizer\Controller\Customize\index\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#22 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/Interception/Chain/Chain.php(67): call_user_func_array(Array, Array)
#23 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Tomrain\\Appcust...', 'dispatch', Object(Tomrain\Appcustomizer\Controller\Customize\index\Interceptor), Array, 'contextPlugin')
#24 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/module-store/App/Action/Plugin/Context.php(106): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
#25 [internal function]: Magento\Store\App\Action\Plugin\Context->aroundDispatch(Object(Tomrain\Appcustomizer\Controller\Customize\index\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#26 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/Interception/Chain/Chain.php(67): call_user_func_array(Array, Array)
#27 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Tomrain\\Appcust...', 'dispatch', Object(Tomrain\Appcustomizer\Controller\Customize\index\Interceptor), Array, 'customer-app-ac...')
#28 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/module-customer/Model/App/Action/ContextPlugin.php(61): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
#29 [internal function]: Magento\Customer\Model\App\Action\ContextPlugin->aroundDispatch(Object(Tomrain\Appcustomizer\Controller\Customize\index\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#30 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/Interception/Chain/Chain.php(67): call_user_func_array(Array, Array)
#31 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Tomrain\\Appcust...', 'dispatch', Object(Tomrain\Appcustomizer\Controller\Customize\index\Interceptor), Array, 'storeCheck')
#32 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/module-store/App/Action/Plugin/StoreCheck.php(44): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
#33 [internal function]: Magento\Store\App\Action\Plugin\StoreCheck->aroundDispatch(Object(Tomrain\Appcustomizer\Controller\Customize\index\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#34 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/Interception/Chain/Chain.php(67): call_user_func_array(Array, Array)
#35 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Tomrain\\Appcust...', 'dispatch', Object(Tomrain\Appcustomizer\Controller\Customize\index\Interceptor), Array, 'weee-app-action...')
#36 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/module-weee/Model/App/Action/ContextPlugin.php(112): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
#37 [internal function]: Magento\Weee\Model\App\Action\ContextPlugin->aroundDispatch(Object(Tomrain\Appcustomizer\Controller\Customize\index\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#38 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/Interception/Chain/Chain.php(67): call_user_func_array(Array, Array)
#39 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('Tomrain\\Appcust...', 'dispatch', Object(Tomrain\Appcustomizer\Controller\Customize\index\Interceptor), Array, 'tax-app-action-...')
#40 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/module-tax/Model/App/Action/ContextPlugin.php(91): Tomrain\Appcustomizer\Controller\Customize\index\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#41 [internal function]: Magento\Tax\Model\App\Action\ContextPlugin->aroundDispatch(Object(Tomrain\Appcustomizer\Controller\Customize\index\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#42 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/Interception/Interceptor.php(142): call_user_func_array(Array, Array)
#43 /var/www/html/appcustomizer-tshirt-M2/var/generation/Tomrain/Appcustomizer/Controller/Customize/index/Interceptor.php(39): Tomrain\Appcustomizer\Controller\Customize\index\Interceptor->___callPlugins('dispatch', Array, Array)
#44 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/App/FrontController.php(55): Tomrain\Appcustomizer\Controller\Customize\index\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#45 [internal function]: Magento\Framework\App\FrontController->dispatch(Object(Magento\Framework\App\Request\Http))
#46 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/Interception/Interceptor.php(74): call_user_func_array(Array, Array)
#47 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/Interception/Chain/Chain.php(70): Magento\Framework\App\FrontController\Interceptor->___callParent('dispatch', Array)
#48 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'requestPreproce...')
#49 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/module-store/App/FrontController/Plugin/RequestPreprocessor.php(89): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
#50 [internal function]: Magento\Store\App\FrontController\Plugin\RequestPreprocessor->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#51 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/Interception/Chain/Chain.php(67): call_user_func_array(Array, Array)
#52 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'install')
#53 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/Module/Plugin/DbStatusValidator.php(69): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
#54 [internal function]: Magento\Framework\Module\Plugin\DbStatusValidator->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#55 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/Interception/Chain/Chain.php(67): call_user_func_array(Array, Array)
#56 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/Interception/Chain/Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'front-controlle...')
#57 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/module-page-cache/Model/App/FrontController/VarnishPlugin.php(55): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}(Object(Magento\Framework\App\Request\Http))
#58 [internal function]: Magento\PageCache\Model\App\FrontController\VarnishPlugin->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#59 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/Interception/Chain/Chain.php(67): call_user_func_array(Array, Array)
#60 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'dispatch', Object(Magento\Framework\App\FrontController\Interceptor), Array, 'front-controlle...')
#61 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/module-page-cache/Model/App/FrontController/BuiltinPlugin.php(73): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#62 [internal function]: Magento\PageCache\Model\App\FrontController\BuiltinPlugin->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#63 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/Interception/Interceptor.php(142): call_user_func_array(Array, Array)
#64 /var/www/html/appcustomizer-tshirt-M2/var/generation/Magento/Framework/App/FrontController/Interceptor.php(26): Magento\Framework\App\FrontController\Interceptor->___callPlugins('dispatch', Array, Array)
#65 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/App/Http.php(115): Magento\Framework\App\FrontController\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#66 /var/www/html/appcustomizer-tshirt-M2/vendor/magento/framework/App/Bootstrap.php(258): Magento\Framework\App\Http->launch()
#67 /var/www/html/appcustomizer-tshirt-M2/index.php(42): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
#68 {main}

When the url passed in the address bar it reaches up to controller action.Problem in $this->_view->loadLayout();

app/code/Tomrain/Appcustomizer/Controller/Customize/index.php

namespace Tomrain\Appcustomizer\Controller\Customize;

use Magento\Framework\App\Action\Context;
use Magento\Framework\File\UploaderFactory;

class Index extends \Magento\Framework\App\Action\Action
{
    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Framework\File\UploaderFactory $uploaderFactory
        )
    {
        $this->uploaderFactory = $uploaderFactory;
        return parent::__construct($context);
    }

    public function execute()
    {
        $this->_view->loadLayout();
        $this->_view->getLayout()->initMessages();
        $this->_view->renderLayout();
    } 
}

app/code/Tomrain/Appcustomizer/view/frontend/layout/appcustomizer_customize_index.xml

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd" layout="1column">
    <body>
        <referenceContainer name="content">
            <block class="Tomrain\Appcustomizer\Block\Customizepage" name="customizepage" template="Tomrain_Appcustomizer::customize/productcustomize.phtml" />
        </referenceContainer>
    </body>
</page>

app/code/Tomrain/Appcustomizer/Block/Customizepage.php

namespace Tomrain\Appcustomizer\Block;

class Customizepage extends \Magento\Framework\View\Element\Template
{
    protected $_storeManager;
    protected $_scopeConfig;

    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
        \Tomrain\Appcustomizer\Helper\Data $helper
    )
    {
        $this->_storeManager = $storeManager;
        $this->_scopeConfig = $scopeConfig;
        $this->helper = $helper;
        parent::__construct($context);
    }

    public function getBaseUrl()
    {
        return $this->helper->getBaseUrl();
    }

    public function getConfigUrl()
    {
        $ConfigUrl =  $this->_scopeConfig->getValue('web/unsecure/base_url', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
        return $ConfigUrl;
    }

}
  • Is your site in production or development, have you tried deleteing var/generation, have you flushed the cache – Dava Gordon Apr 12 at 9:43
0

Each block takes array $data = [] as parameter.(conventionally included at last) Hence when you call parent constructor it should look something like this parent::__construct($context, $data); Change that and let me know.

  • Can you double check folder name with small and capital letter. – Sunil Patel May 13 '17 at 7:23
  • I have passed array $data = [] as parameter in __construct and changed parent::__construct($context, $data);but is not working – S.Elavarasan May 13 '17 at 8:15
  • Does it give you same error? – Abhishek Jakhotiya May 13 '17 at 8:18
  • yes it gives same error. – S.Elavarasan May 13 '17 at 8:22
  • 1
    I have found the error by running setup:di:compile command. Error in helper file public function __construct( \Magento\Framework\App\Helper\Context $context, \Magento\Store\Model\StoreManagerInterface $storeManager, ) i.e. added extra comma after secound parameter.I have injected helper file in block file so the error occured – S.Elavarasan May 13 '17 at 11:50
0

Just flush, check permission ...I fixed by:

sudo php bin/magento cache:flush
sudo chmod 777 -R generated/* var/* pub/*

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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