Magento 2 - Cannot instantiate abstract class

When you make an extension for Magento, you may face an issue like this:

Cannot instantiate abstract class Magento\\Framework\\Model\\ResourceModel\\AbstractResource at

or

Cannot instantiate abstract class Magento\Framework\Model\ResourceModel\AbstractResource in

There are many reasons, but this may be a common case. I give you some tips so you can try to fix it yourself.

This often happens when a third-party extension has a default parameter in between the __construct() arguments instead of at the end.

Please check which action you're performing while getting this error. One of the classes involved in this action can have a default parameter in between, like below:

public function __construct(
Template\Context $context,
\PL\Snippets\Model\VideoFactory $videoFactory,
\Magento\Framework\Registry $coreRegistry,
array $data = [],
\PL\Snippets\Helper\Data $snippetHelper
) {
parent::__construct($context, $data);
$this->videoFactory = $videoFactory;
$this->_coreRegistry = $coreRegistry;
$this->snippetHelper = $snippetHelper;
}


You need to move array $data = [] to the last position because it has a default value.

public function __construct(
Template\Context $context,
\PL\Snippets\Model\VideoFactory $videoFactory,
\Magento\Framework\Registry $coreRegistry,
\PL\Snippets\Helper\Data $snippetHelper,
array $data = []
) {
parent::__construct($context, $data);
$this->videoFactory = $videoFactory;
$this->_coreRegistry = $coreRegistry;
$this->snippetHelper = $snippetHelper;
}

 

Back to Top