Call to a member function crop() on null

I got the error why try to output the thumbnails. Here is my code

 <?php
	        $items = $page->children()->listed()->paginate(12);

		//output image
	        foreach ($items as $item):
	        	$thumb = $item->thumbnail();	
	        	if($item->thumbnail()->isNotEmpty()){
	        		$thumb = $item->thumbnail()->toFile();
	   			}
	   			else{
	   				$thumb = $item->image();
	   			}
	         ?>

	        	<a href="<?= $item->url() ?>">
	        		<img class="product-thumb" 
	        		 src="<?= $thumb->crop(400,400)->url() ?> "  alt="<?= $item->title() ?>" />
	        	</a>
<?php endforeach ?>

The error appears when I made some changes in the blueprint and uploaded some files in the panel. It worked fine before.

Thanks

You are not checking if your $thumb is actually an object:

 <?php
 $items = $page->children()->listed()->paginate(12);

//output image
foreach ($items as $item):
  $thumb = $item->thumbnail()->toFile() ?? $item->image();
?>
    <?php if ($thumb): ?>
        <a href="<?= $item->url() ?>">
            <img class="product-thumb" 
        src="<?= $thumb->crop(400,400)->url() ?> "  alt="<?= $item->title() ?>" />
        </a>
    <?php endif ?>
<?php endforeach ?>

Thanks so much. It works fine now!