Call to a member function toHtml() on null Magento 2Magento 2 : How to get product get images for thumbnail?Fatal error: Call to a member function create() on null in Magento 2Magento 2 : Fatal error: Uncaught Error: Call to a member function dispatch() | Store InformationFatal error: Call to a member functionMagento 2 Block error of Call to a member function create() on nullGet item collection by sku Magento 2Magento2: Fatal error: Uncaught Error: Call to a member function setProduct()Magento 2 : Fatal error: Uncaught Error: Call to a member function dispatch()Fatal error: Uncaught Error: Call to a member function setProductCollection() on boolean inFatal Error: 'Uncaught Error: Call to a member function setCustomPrice() on boolean magento 2.3Uncaught Error: Call to a member function dispatch() on null ViewElementAbstractBlock.php on line 652

A STL-like vector implementation in C++

Can humans ever directly see a few photons at a time? Can a human see a single photon?

Why do all the teams that I have worked with always finish a sprint without completion of all the stories?

Hand soldering SMD 1206 components

Do I have any obligations to my PhD supervisor's requests after I have graduated?

Sci fi short story, robot city that nags people about health

What is the origin of Scooby-Doo's name?

What reason would an alien civilization have for building a Dyson Sphere (or Swarm) if cheap Nuclear fusion is available?

Find the C-factor of a vote

Did Karl Marx ever use any example that involved cotton and dollars to illustrate the way capital and surplus value were generated?

How do I turn off a repeating trade?

What does "play with your toy’s toys" mean?

Trainee keeps missing deadlines for independent learning

C-152 carb heat on before landing in hot weather?

Long term BTC investing

Can we put equal sign after aggregate functions in sql?

How does Powershell create fake drive labels in Windows?

First-year PhD giving a talk among well-established researchers in the field

Does this Wild Magic result affect the sorcerer or just other creatures?

Archery in modern conflicts

Interaction between Leyline of Anticipation and Teferi, Time Raveler

How does a blind passenger not die, if driver becomes unconscious

Where can I find a database of galactic spectra?

How to make clear to people I don't want to answer their "Where are you from?" question?



Call to a member function toHtml() on null Magento 2


Magento 2 : How to get product get images for thumbnail?Fatal error: Call to a member function create() on null in Magento 2Magento 2 : Fatal error: Uncaught Error: Call to a member function dispatch() | Store InformationFatal error: Call to a member functionMagento 2 Block error of Call to a member function create() on nullGet item collection by sku Magento 2Magento2: Fatal error: Uncaught Error: Call to a member function setProduct()Magento 2 : Fatal error: Uncaught Error: Call to a member function dispatch()Fatal error: Uncaught Error: Call to a member function setProductCollection() on boolean inFatal Error: 'Uncaught Error: Call to a member function setCustomPrice() on boolean magento 2.3Uncaught Error: Call to a member function dispatch() on null ViewElementAbstractBlock.php on line 652






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















enter image description here I am trying to show Product Collection in .phtml file of custom module



<a href="<?= /* @escapeNotVerified */ $block->getProductUrl($_item) ?>" class="product photo product-item-photo">
<?= $block->getImage($_item, $image)->toHtml() ?>
</a>


in this line i am getting error as




Fatal error: Uncaught Error: Call to a member function toHtml() on
null




anyone please help



i got product Collection By Product ID



$this->_itemCollection=[];
foreach ($collection as $value)
$product = $this->_productRepository->getById($value->getProductId());
array_push($this->_itemCollection, $product);

return $this;









share|improve this question
























  • $block->getImage($_item, $image) returns null. that's what the exception tells you

    – Philipp Sander
    Jun 14 at 11:28











  • add getImage() function code

    – Rk Rathod
    Jun 14 at 11:34












  • can u place that code??

    – Waqar Ali
    Jun 14 at 11:36











  • check my answer

    – Rk Rathod
    Jun 14 at 11:44

















0















enter image description here I am trying to show Product Collection in .phtml file of custom module



<a href="<?= /* @escapeNotVerified */ $block->getProductUrl($_item) ?>" class="product photo product-item-photo">
<?= $block->getImage($_item, $image)->toHtml() ?>
</a>


in this line i am getting error as




Fatal error: Uncaught Error: Call to a member function toHtml() on
null




anyone please help



i got product Collection By Product ID



$this->_itemCollection=[];
foreach ($collection as $value)
$product = $this->_productRepository->getById($value->getProductId());
array_push($this->_itemCollection, $product);

return $this;









share|improve this question
























  • $block->getImage($_item, $image) returns null. that's what the exception tells you

    – Philipp Sander
    Jun 14 at 11:28











  • add getImage() function code

    – Rk Rathod
    Jun 14 at 11:34












  • can u place that code??

    – Waqar Ali
    Jun 14 at 11:36











  • check my answer

    – Rk Rathod
    Jun 14 at 11:44













0












0








0








enter image description here I am trying to show Product Collection in .phtml file of custom module



<a href="<?= /* @escapeNotVerified */ $block->getProductUrl($_item) ?>" class="product photo product-item-photo">
<?= $block->getImage($_item, $image)->toHtml() ?>
</a>


in this line i am getting error as




Fatal error: Uncaught Error: Call to a member function toHtml() on
null




anyone please help



i got product Collection By Product ID



$this->_itemCollection=[];
foreach ($collection as $value)
$product = $this->_productRepository->getById($value->getProductId());
array_push($this->_itemCollection, $product);

return $this;









share|improve this question
















enter image description here I am trying to show Product Collection in .phtml file of custom module



<a href="<?= /* @escapeNotVerified */ $block->getProductUrl($_item) ?>" class="product photo product-item-photo">
<?= $block->getImage($_item, $image)->toHtml() ?>
</a>


in this line i am getting error as




Fatal error: Uncaught Error: Call to a member function toHtml() on
null




anyone please help



i got product Collection By Product ID



$this->_itemCollection=[];
foreach ($collection as $value)
$product = $this->_productRepository->getById($value->getProductId());
array_push($this->_itemCollection, $product);

return $this;






magento2 php






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 14 at 12:00









Aasim Goriya

3,2371 gold badge11 silver badges43 bronze badges




3,2371 gold badge11 silver badges43 bronze badges










asked Jun 14 at 11:21









Waqar AliWaqar Ali

10711 bronze badges




10711 bronze badges












  • $block->getImage($_item, $image) returns null. that's what the exception tells you

    – Philipp Sander
    Jun 14 at 11:28











  • add getImage() function code

    – Rk Rathod
    Jun 14 at 11:34












  • can u place that code??

    – Waqar Ali
    Jun 14 at 11:36











  • check my answer

    – Rk Rathod
    Jun 14 at 11:44

















  • $block->getImage($_item, $image) returns null. that's what the exception tells you

    – Philipp Sander
    Jun 14 at 11:28











  • add getImage() function code

    – Rk Rathod
    Jun 14 at 11:34












  • can u place that code??

    – Waqar Ali
    Jun 14 at 11:36











  • check my answer

    – Rk Rathod
    Jun 14 at 11:44
















$block->getImage($_item, $image) returns null. that's what the exception tells you

– Philipp Sander
Jun 14 at 11:28





$block->getImage($_item, $image) returns null. that's what the exception tells you

– Philipp Sander
Jun 14 at 11:28













add getImage() function code

– Rk Rathod
Jun 14 at 11:34






add getImage() function code

– Rk Rathod
Jun 14 at 11:34














can u place that code??

– Waqar Ali
Jun 14 at 11:36





can u place that code??

– Waqar Ali
Jun 14 at 11:36













check my answer

– Rk Rathod
Jun 14 at 11:44





check my answer

– Rk Rathod
Jun 14 at 11:44










1 Answer
1






active

oldest

votes


















1















.phtml file




<a href="<?= /* @escapeNotVerified */ $block->getProductUrl($_item) ?>" class="product photo product-item-photo">
<?= $this->getImage($_item, $image)->toHtml() ?>
</a>



getImage() Function in Block File




 <?php

namespace VendorModuleBlock;

class file_name extends Template

protected $imageBuilder;

public function __construct(
MagentoCatalogBlockProductContext $contextImage,
array $data = []
)

$this->imageBuilder = $contextImage->getImageBuilder();
parent::__construct($context, $data);

public function getImage($product, $imageId, $attributes = [])

return $this->imageBuilder->setProduct($product)
->setImageId($imageId)
->setAttributes($attributes)
->create();







share|improve this answer

























  • thank you its working but i am getting an image small

    – Waqar Ali
    Jun 14 at 11:50











  • which type image you get ?

    – Rk Rathod
    Jun 14 at 11:51











  • image size is very small i

    – Waqar Ali
    Jun 14 at 11:55











  • please attach screenshot

    – Rk Rathod
    Jun 14 at 11:56






  • 1





    magento.stackexchange.com/a/234745/72911 check this

    – Rk Rathod
    Jun 14 at 12:03













Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f278388%2fcall-to-a-member-function-tohtml-on-null-magento-2%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1















.phtml file




<a href="<?= /* @escapeNotVerified */ $block->getProductUrl($_item) ?>" class="product photo product-item-photo">
<?= $this->getImage($_item, $image)->toHtml() ?>
</a>



getImage() Function in Block File




 <?php

namespace VendorModuleBlock;

class file_name extends Template

protected $imageBuilder;

public function __construct(
MagentoCatalogBlockProductContext $contextImage,
array $data = []
)

$this->imageBuilder = $contextImage->getImageBuilder();
parent::__construct($context, $data);

public function getImage($product, $imageId, $attributes = [])

return $this->imageBuilder->setProduct($product)
->setImageId($imageId)
->setAttributes($attributes)
->create();







share|improve this answer

























  • thank you its working but i am getting an image small

    – Waqar Ali
    Jun 14 at 11:50











  • which type image you get ?

    – Rk Rathod
    Jun 14 at 11:51











  • image size is very small i

    – Waqar Ali
    Jun 14 at 11:55











  • please attach screenshot

    – Rk Rathod
    Jun 14 at 11:56






  • 1





    magento.stackexchange.com/a/234745/72911 check this

    – Rk Rathod
    Jun 14 at 12:03















1















.phtml file




<a href="<?= /* @escapeNotVerified */ $block->getProductUrl($_item) ?>" class="product photo product-item-photo">
<?= $this->getImage($_item, $image)->toHtml() ?>
</a>



getImage() Function in Block File




 <?php

namespace VendorModuleBlock;

class file_name extends Template

protected $imageBuilder;

public function __construct(
MagentoCatalogBlockProductContext $contextImage,
array $data = []
)

$this->imageBuilder = $contextImage->getImageBuilder();
parent::__construct($context, $data);

public function getImage($product, $imageId, $attributes = [])

return $this->imageBuilder->setProduct($product)
->setImageId($imageId)
->setAttributes($attributes)
->create();







share|improve this answer

























  • thank you its working but i am getting an image small

    – Waqar Ali
    Jun 14 at 11:50











  • which type image you get ?

    – Rk Rathod
    Jun 14 at 11:51











  • image size is very small i

    – Waqar Ali
    Jun 14 at 11:55











  • please attach screenshot

    – Rk Rathod
    Jun 14 at 11:56






  • 1





    magento.stackexchange.com/a/234745/72911 check this

    – Rk Rathod
    Jun 14 at 12:03













1












1








1








.phtml file




<a href="<?= /* @escapeNotVerified */ $block->getProductUrl($_item) ?>" class="product photo product-item-photo">
<?= $this->getImage($_item, $image)->toHtml() ?>
</a>



getImage() Function in Block File




 <?php

namespace VendorModuleBlock;

class file_name extends Template

protected $imageBuilder;

public function __construct(
MagentoCatalogBlockProductContext $contextImage,
array $data = []
)

$this->imageBuilder = $contextImage->getImageBuilder();
parent::__construct($context, $data);

public function getImage($product, $imageId, $attributes = [])

return $this->imageBuilder->setProduct($product)
->setImageId($imageId)
->setAttributes($attributes)
->create();







share|improve this answer
















.phtml file




<a href="<?= /* @escapeNotVerified */ $block->getProductUrl($_item) ?>" class="product photo product-item-photo">
<?= $this->getImage($_item, $image)->toHtml() ?>
</a>



getImage() Function in Block File




 <?php

namespace VendorModuleBlock;

class file_name extends Template

protected $imageBuilder;

public function __construct(
MagentoCatalogBlockProductContext $contextImage,
array $data = []
)

$this->imageBuilder = $contextImage->getImageBuilder();
parent::__construct($context, $data);

public function getImage($product, $imageId, $attributes = [])

return $this->imageBuilder->setProduct($product)
->setImageId($imageId)
->setAttributes($attributes)
->create();








share|improve this answer














share|improve this answer



share|improve this answer








edited Jun 14 at 12:01









Aasim Goriya

3,2371 gold badge11 silver badges43 bronze badges




3,2371 gold badge11 silver badges43 bronze badges










answered Jun 14 at 11:44









Rk RathodRk Rathod

2,3703 silver badges16 bronze badges




2,3703 silver badges16 bronze badges












  • thank you its working but i am getting an image small

    – Waqar Ali
    Jun 14 at 11:50











  • which type image you get ?

    – Rk Rathod
    Jun 14 at 11:51











  • image size is very small i

    – Waqar Ali
    Jun 14 at 11:55











  • please attach screenshot

    – Rk Rathod
    Jun 14 at 11:56






  • 1





    magento.stackexchange.com/a/234745/72911 check this

    – Rk Rathod
    Jun 14 at 12:03

















  • thank you its working but i am getting an image small

    – Waqar Ali
    Jun 14 at 11:50











  • which type image you get ?

    – Rk Rathod
    Jun 14 at 11:51











  • image size is very small i

    – Waqar Ali
    Jun 14 at 11:55











  • please attach screenshot

    – Rk Rathod
    Jun 14 at 11:56






  • 1





    magento.stackexchange.com/a/234745/72911 check this

    – Rk Rathod
    Jun 14 at 12:03
















thank you its working but i am getting an image small

– Waqar Ali
Jun 14 at 11:50





thank you its working but i am getting an image small

– Waqar Ali
Jun 14 at 11:50













which type image you get ?

– Rk Rathod
Jun 14 at 11:51





which type image you get ?

– Rk Rathod
Jun 14 at 11:51













image size is very small i

– Waqar Ali
Jun 14 at 11:55





image size is very small i

– Waqar Ali
Jun 14 at 11:55













please attach screenshot

– Rk Rathod
Jun 14 at 11:56





please attach screenshot

– Rk Rathod
Jun 14 at 11:56




1




1





magento.stackexchange.com/a/234745/72911 check this

– Rk Rathod
Jun 14 at 12:03





magento.stackexchange.com/a/234745/72911 check this

– Rk Rathod
Jun 14 at 12:03

















draft saved

draft discarded
















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f278388%2fcall-to-a-member-function-tohtml-on-null-magento-2%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form