Magento 2 Uncaught TypeError: Argument 1 passed to __construct() must be an instance of Magento\Backend\Block\Template\Context

Magento 2 Uncaught TypeError: Argument 1 passed to __construct() must be an instance of Magento\Backend\Block\Template\Context

在 Magento 2.2 中,我创建了一个模块,但出现了这个错误。

Uncaught TypeError: Argument 1 passed to __construct() must be an instance of Magento\Backend\Block\Template\Context, instance of Magento\Framework\ObjectManager\ObjectManager given

我的文件路径app\code\Namespace\Modulename\Block\Adminhtml\Exporter\Edit\Tab\Form.php

<?php
namespace Namespace\Modulename\Block\Adminhtml\Exporter\Edit\Tab;

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

    public function __construct(
       \Magento\Backend\Block\Template\Context $context,
       \Magento\Framework\Registry $registry,
       \Magento\Framework\Data\FormFactory $formFactory,
       \Raveinfosys\Orderexporter\Model\Exporter $exporter,
        array $data = []
    ) {
        $this->exporter = $exporter;
        $this->_formFactory = $formFactory;

        parent::__construct($context, $registry, $formFactory, $data);
    }

他们在

处显示错误

public function __construct

一般来说,Magento 在 var/generation 文件夹中缓存构造函数,所以如果您清除 var/generation 内容 Magento 将重新生成拦截器。

rm -rf var/generation var/di

Clearing var/generation and var/di could fix this issue.