Magento2 Blocks – Class Not Found Even When It Exists

blocksclassmagento2

I have a custom module and i tried to extend this class in my Image.php file: Magento\Framework\Data\Form\Element\Image

namespace Vendor\Namespace\Block\Adminhtml\Form\Element;

class Image extends Magento\Framework\Data\Form\Element\Image
{ 
    /**
     * Get image preview url
     *
     * @return string
     */
    protected function _getUrl()
    {
        return $this->getValue();
    }
}

When i run the compile command i receive this err:
14% 1 sec 52.0 MiBPHP Fatal error: Class 'vendor\namespace\Block\Adminhtml\Form\Element\Magento\Framework\Data\Form\Element\Image' not found in app/code/vendorm/namespace/Block/Adminhtml/Form/Element/Image.php on line 9.

Even this class exist at this path, i still receive this error.

Does anyone know why this happen?

Best Answer

Try :

class Image extends \Magento\Framework\Data\Form\Element\Image

Without the \ Magento is looking within the module for the class.