cancel
Showing results for 
Search instead for 
Did you mean: 

Type Error occurred when creating object ?

SOLVED

Type Error occurred when creating object ?

I got this error, what is this error and how can i fix this.

1 exception(s):
Exception #0 (Magento\Framework\Exception\RuntimeException): Type Error occurred when creating object: Rakuten\MemberCard\Block\Adminhtml\Card\Import, Magento\Backend\Block\Widget\Form\Generic::__construct(): Argument #2 ($registry) must be of type Magento\Framework\Registry, array given, called in /var/www/html/rakuten_magento/app/code/Rakuten/MemberCard/Block/Adminhtml/Card/Import.php on line 23

Exception #0 (Magento\Framework\Exception\RuntimeException): Type Error occurred when creating object: Rakuten\MemberCard\Block\Adminhtml\Card\Import, Magento\Backend\Block\Widget\Form\Generic::__construct(): Argument #2 ($registry) must be of type Magento\Framework\Registry, array given, called in /var/www/html/rakuten_magento/app/code/Rakuten/MemberCard/Block/Adminhtml/Card/Import.php on line 23
<pre>#1 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create() called at [vendor/magento/framework/ObjectManager/ObjectManager.php:56]
#2 Magento\Framework\ObjectManager\ObjectManager->create() called at [vendor/magento/framework/View/Element/BlockFactory.php:44]
#3 Magento\Framework\View\Element\BlockFactory->createBlock() called at [vendor/magento/framework/View/Layout/Generator/Block.php:272]
#4 Magento\Framework\View\Layout\Generator\Block->getBlockInstance() called at [vendor/magento/framework/View/Layout/Generator/Block.php:252]
#5 Magento\Framework\View\Layout\Generator\Block->createBlock() called at [vendor/magento/framework/View/Layout/Generator/Block.php:229]
#6 Magento\Framework\View\Layout\Generator\Block->generateBlock() called at [vendor/magento/framework/View/Layout/Generator/Block.php:134]
#7 Magento\Framework\View\Layout\Generator\Block->process() called at [vendor/magento/framework/View/Layout/GeneratorPool.php:93]
#8 Magento\Framework\View\Layout\GeneratorPool->process() called at [vendor/magento/framework/View/Layout.php:365]
#9 Magento\Framework\View\Layout->generateElements() called at [generated/code/Magento/Framework/View/Layout/Interceptor.php:68]
#10 Magento\Framework\View\Layout\Interceptor->generateElements() called at [vendor/magento/framework/View/Layout/Builder.php:129]
#11 Magento\Framework\View\Layout\Builder->generateLayoutBlocks() called at [vendor/magento/framework/View/Page/Builder.php:65]
#12 Magento\Framework\View\Page\Builder->generateLayoutBlocks() called at [vendor/magento/framework/View/Layout/Builder.php:65]
#13 Magento\Framework\View\Layout\Builder->build() called at [vendor/magento/framework/View/Page/Config.php:227]
#14 Magento\Framework\View\Page\Config->build() called at [vendor/magento/framework/View/Page/Config.php:250]
#15 Magento\Framework\View\Page\Config->getTitle() called at [app/code/Rakuten/MemberCard/Controller/Adminhtml/Card/Import.php:32]
#16 Rakuten\MemberCard\Controller\Adminhtml\Card\Import->execute() called at [vendor/magento/framework/Interception/Interceptor.php:58]
#17 Rakuten\MemberCard\Controller\Adminhtml\Card\Import\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138]
#18 Rakuten\MemberCard\Controller\Adminhtml\Card\Import\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#19 Rakuten\MemberCard\Controller\Adminhtml\Card\Import\Interceptor->___callPlugins() called at [generated/code/Rakuten/MemberCard/Controller/Adminhtml/Card/Import/Interceptor.php:23]
#20 Rakuten\MemberCard\Controller\Adminhtml\Card\Import\Interceptor->execute() called at [vendor/magento/framework/App/Action/Action.php:111]
#21 Magento\Framework\App\Action\Action->dispatch() called at [vendor/magento/module-backend/App/AbstractAction.php:151]
#22 Magento\Backend\App\AbstractAction->dispatch() called at [vendor/magento/framework/Interception/Interceptor.php:58]
#23 Rakuten\MemberCard\Controller\Adminhtml\Card\Import\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138]
#24 Rakuten\MemberCard\Controller\Adminhtml\Card\Import\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/module-backend/App/Action/Plugin/Authentication.php:145]
#25 Magento\Backend\App\Action\Plugin\Authentication->aroundDispatch() called at [vendor/magento/framework/Interception/Interceptor.php:135]
#26 Rakuten\MemberCard\Controller\Adminhtml\Card\Import\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#27 Rakuten\MemberCard\Controller\Adminhtml\Card\Import\Interceptor->___callPlugins() called at [generated/code/Rakuten/MemberCard/Controller/Adminhtml/Card/Import/Interceptor.php:32]
#28 Rakuten\MemberCard\Controller\Adminhtml\Card\Import\Interceptor->dispatch() called at [vendor/magento/framework/App/FrontController.php:245]
#29 Magento\Framework\App\FrontController->getActionResponse() called at [vendor/magento/framework/App/FrontController.php:212]
#30 Magento\Framework\App\FrontController->processRequest() called at [vendor/magento/framework/App/FrontController.php:147]
#31 Magento\Framework\App\FrontController->dispatch() called at [vendor/magento/framework/Interception/Interceptor.php:58]
#32 Magento\Framework\App\FrontController\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138]
#33 Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#34 Magento\Framework\App\FrontController\Interceptor->___callPlugins() called at [generated/code/Magento/Framework/App/FrontController/Interceptor.php:23]
#35 Magento\Framework\App\FrontController\Interceptor->dispatch() called at [vendor/magento/framework/App/Http.php:116]
#36 Magento\Framework\App\Http->launch() called at [generated/code/Magento/Framework/App/Http/Interceptor.php:23]
#37 Magento\Framework\App\Http\Interceptor->launch() called at [vendor/magento/framework/App/Bootstrap.php:264]
#38 Magento\Framework\App\Bootstrap->run() called at [pub/index.php:30]
</pre>
2 ACCEPTED SOLUTIONS

Accepted Solutions

Re: Type Error occurred when creating object ?

Hi @annq3sivn4281 

 

Please replace your constructor with below change and execute compilation again.

 

public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\Data\FormFactory $formFactory,
\Magento\Framework\View\Asset\Repository $assetRepo,
array $data = []
) {
$this->_assetRepo = $assetRepo;
parent::__construct($context, $registry, $formFactory, $data);
}

 

I have done changes in parent::__construct() parameters orders. Please replace with above and execute compile.

 

Problem solved? Click Accept as Solution!

 

Hope it helps!

Thanks

Ankit Jasani

View solution in original post

Re: Type Error occurred when creating object ?

It is actually work but  i still need to run some command to reset my page:

php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy -f
sudo chmod -R 777 var pub generated
php bin/magento c:f

View solution in original post

6 REPLIES 6

Re: Type Error occurred when creating object ?

Hi @annq3sivn4281 ,

 

Can you please provide content that you have added in constructor for this file?

/var/www/html/rakuten_magento/app/code/Rakuten/MemberCard/Block/Adminhtml/Card/Import.php on line 23

 

Hope it helps!

Thanks

Ankit Jasani

Re: Type Error occurred when creating object ?

Here, i do not know what happen with $registry ?

<?php

namespace Rakuten\MemberCard\Block\Adminhtml\Card;

class Import extends \Magento\Backend\Block\Widget\Form\Generic implements \Magento\Backend\Block\Widget\Tab\TabInterface
{
    protected $_assetRepo;

    /**
     * Import constructor.
     * @param \Magento\Backend\Block\Template\Context $context
     * @param array $data
     */
    public function __construct(
        \Magento\Backend\Block\Template\Context $context,
        \Magento\Framework\Registry $registry,
        \Magento\Framework\Data\FormFactory $formFactory,
        \Magento\Framework\View\Asset\Repository $assetRepo,
        array $data = []
    )
    {
        $this->_assetRepo = $assetRepo;
        parent::__construct($context, $data, $registry, $formFactory);
    }

    /**
     * Prepare form
     *
     * @return $this
     */
    protected function _prepareForm()

    {

        $path = $this->_assetRepo->getUrl("vendor_module::importsample/sample.csv");

        $form = $this->_formFactory->create();
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $storemanager = $objectManager->create('Magento\Store\Model\StoreManagerInterface');

        $fieldset = $form->addFieldset(
            'base_fieldset',
            [
                'legend' => __('Import Pincodes'),
                'class' => 'fieldset-wide'
            ]
        );

        $importdata_script = $fieldset->addField(
            'file',
            'file',
            [
                'name' => 'file',
                'label' => __('Upload File'),
                'title' => __('Upload File'),
                'required' => true,
            ]
        );

        $importdata_script->setAfterElementHtml("
        <span id='sample-file-span' ><a id='sample-file-link' href='" . $path . "'  >Download Sample File</a></span>
        ");

        $this->setForm($form);
        return parent::_prepareForm();
    }

    /**
     * Prepare label for tab
     *
     * @return string
     */
    public function getTabLabel()
    {
        return __('Import Pincodes');
    }

    /**
     * Prepare title for tab
     *
     * @return string
     */
    public function getTabTitle()
    {
        return $this->getTabLabel();
    }

    /**
     * Can show tab in tabs
     *
     * @return boolean
     */
    public function canShowTab()
    {
        return true;
    }

    /**
     * Tab is hidden
     *
     * @return boolean
     */
    public function isHidden()
    {
        return false;
    }

}

Re: Type Error occurred when creating object ?

Hi @annq3sivn4281 ,

 

As I can see you haven't used $registry anywhere except constructor.

 

So, try one thing, remove $registry from constructor and compile again.

 

Remove below lines:

\Magento\Framework\Registry $registry,

and

Remove $registry from parent::__construct()

 

OR

 

If you need $registry in your current block then define variable and remove it from parent::__construct() and use it like $this->registry = $registry; after $this->_assetRepo = $assetRepo; line.

 

Problem solved? Click Accept as Solution!

 

Hope it helps!

Thanks

Ankit Jasani

Re: Type Error occurred when creating object ?

i did like you said but it still show the same error. It still show that $registry in my import file

Re: Type Error occurred when creating object ?

Hi @annq3sivn4281 

 

Please replace your constructor with below change and execute compilation again.

 

public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\Data\FormFactory $formFactory,
\Magento\Framework\View\Asset\Repository $assetRepo,
array $data = []
) {
$this->_assetRepo = $assetRepo;
parent::__construct($context, $registry, $formFactory, $data);
}

 

I have done changes in parent::__construct() parameters orders. Please replace with above and execute compile.

 

Problem solved? Click Accept as Solution!

 

Hope it helps!

Thanks

Ankit Jasani

Re: Type Error occurred when creating object ?

It is actually work but  i still need to run some command to reset my page:

php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy -f
sudo chmod -R 777 var pub generated
php bin/magento c:f