6

In Continue with

Magento 2: Error during compilation

I have below error while running

php bin/magento setup:di:compile

Errors during compilation:
        Custom\Module\Model\ResourceModel\Messages\Grid\Collection
                Incompatible argument type: Required type: \Magento\Framework\DB\Adapter\AdapterInterface. Actual type: \Magento\Store\Model\StoreManagerInterface; File:
D:/wamp/www/smint/magento/app/code/Custom/Module/Model/ResourceModel/Messages/Grid/Collection.php

        Custom\Module\Model\ResourceModel\Posts\Grid\Collection
                Incompatible argument type: Required type: \Magento\Framework\DB\Adapter\AdapterInterface. Actual type: \Magento\Store\Model\StoreManagerInterface; File:
D:/wamp/www/smint/magento/app/code/Custom/Module/Model/ResourceModel/Posts/Grid/Collection.php

Total Errors Count: 2

app\code\Custom\Module\Model\ResourceModel\Posts\Grid\Collection.php

namespace Custom\Module\Model\ResourceModel\Posts\Grid;

use Magento\Framework\Api\Search\SearchResultInterface;
use Magento\Framework\Search\AggregationInterface;
use Magento\Framework\DB\Adapter\AdapterInterface;
use Custom\Module\Model\ResourceModel\Posts\Collection as PostsCollection;

/**
 * Collection for displaying grid of etrade posts
 */
class Collection extends PostsCollection implements SearchResultInterface
{
    public function __construct(
        \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory,
        \Psr\Log\LoggerInterface $logger,
        \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
        \Magento\Framework\Event\ManagerInterface $eventManager,
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        \Magento\Framework\EntityManager\MetadataPool $metadataPool,
        $mainTable,
        $eventPrefix,
        $eventObject,
        $resourceModel,
        $model = 'Magento\Framework\View\Element\UiComponent\DataProvider\Document',
        $connection = null,
        \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null
    ) {
        parent::__construct(
            $entityFactory,
            $logger,
            $fetchStrategy,
            $eventManager,
            $storeManager,
            $metadataPool,
            $connection,
            $resource
        );
        $this->_eventPrefix = $eventPrefix;
        $this->_eventObject = $eventObject;
        $this->_init($model, $resourceModel);
        $this->setMainTable($mainTable);
    }
}

app\code\Custom\Module\Model\ResourceModel\Posts\Collection.php

namespace Custom\Module\Model\ResourceModel\Posts;

use Custom\Module\Api\Data\PostsInterface;
use Custom\Module\Model\ResourceModel\AbstractCollection;

class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection {

    protected $_idFieldName = 'posts_id';

    protected function _construct() {
        $this->_init(
                'Custom\Module\Model\Posts', 'Custom\Module\Model\ResourceModel\Posts');
    }

}

How to solve above complication errors?

2
  • Please post your : Custom\Module\Model\ResourceModel\Posts\Collection. Oct 20, 2016 at 4:20
  • Hi @KhoaTruongDinh Updated in Question. Thanks
    – Jackson
    Oct 20, 2016 at 4:23

1 Answer 1

8

This is because your parent constructor has redundant arguments or not correct . In your case, need to remove arguments: $storeManager and $metadataPool.

app\code\Custom\Module\Model\ResourceModel\Posts\Grid\Collection.php

parent::__construct(
        $entityFactory,
        $logger,
        $fetchStrategy,
        $eventManager,
        //$storeManager, <= Remove it
        //$metadataPool, <= Remove it
        $connection,
        $resource
    );
3
  • From app\code\Custom\Module\Model\ResourceModel\Posts\Grid\Collection.php need to remove right?
    – Jackson
    Oct 20, 2016 at 5:55
  • Yes, it is @AnkitShah Oct 20, 2016 at 5:58
  • 1
    Thanks it solved complication error.I hope it's not going to affect any functionality.
    – Jackson
    Oct 20, 2016 at 6:25

Your Answer

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

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