- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Call to a member function get() on null in ObjectManager/Factory/AbstractFactory.php
Hi,
I have created magento 2 module (a Magento2 Cron job, no Web stuff). Before it gets fully autogenerated, i.e. before the cron job Synchronize->execute() is even started, the whole thing runs into a problem.
The trace shows that the problem emerges preparing dependency injection for Panlab\Panstore\Model\Producer. This is my class ... that is the Panlab\Panstore things are my module.
However, it seems as though the problem pertains to internals of ObjectManager factory dynamic generation. You can see the trace here.
I am sure the problem is on my side; however, the trace gives no clues as to what I am actually doing wrong. Perhaps I maintain a class in a namespace where it shouldn't be ... Any help would be appreciated.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Call to a member function get() on null in ObjectManager/Factory/AbstractFactory.php
I think I have found the reason for the problem: in the ./Model subsection of your module, there should be nothing else but the objects which are coupled with appropriate ResourceModel clases (model + collection folders).
If this thing is missing, you will run into the same kind of a problem as I have ... dynamic generator does not find the expected classes in ResourceModel and conveys NULL instead of definite objects in certain dependency injection procedures.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Call to a member function get() on null in ObjectManager/Factory/AbstractFactory.php
Unfortunately this did not solve the problem I still have the same error. The trace is different, but the error the same. This is the full PHP error log ... please search for "PHP Fatal error" ... any help appreciated ...
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Call to a member function get() on null in ObjectManager/Factory/AbstractFactory.php
I have produced a minimal codesample for my problem. You can view it here. It is a very small Magento 2 module implementation (only a few lines). If you run it inside app/code on a fresh Mageno 2 installation, you will get this error
PHP Fatal error: Call to a member function get() on null in /var/www/jesej.si/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 126
Anyone understands why ?
P.S. Please check also the full transcript of the PHP error log after running the module.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Call to a member function get() on null in ObjectManager/Factory/AbstractFactory.php
class Synchronize {
protected $objectManager;
__construct(\Magento\Framework\App\ObjectManager $objectManager) {
$this->objectManager = $objectManager;
}
}
Put that class as the only class in the root folder of the model in Synchronize.php, run the magento cron ... and baaaam => you get the null pointer exception.
It is obvious that my module has nothing to do with it. The question is, why dependency injection is not working fo ObjectManager ... interestingly, only for object manager, because I was able to use this approach to successfuly inject dependency for a plethora of other Magento2 stuff (indexers ...). IMHO this is Magento2 bug.
I was able to circumvent this problem by
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
This works perfectly.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Call to a member function get() on null in ObjectManager/Factory/AbstractFactory.php
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: Call to a member function get() on null in ObjectManager/Factory/AbstractFactory.php
Don't inject the OM directly
\Magento\Framework\App\ObjectManager
but instead its interface
\Magento\Framework\ObjectManagerInterface $objectmanager
.