use \Magento\Framework\Message\ManagerInterface;
use below code in your file to add messages,
protected _messageManager;
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Framework\Message\ManagerInterface $messageManager
) {
parent::__construct($context);
$this->_messageManager = $messageManager;
}
and then add below functions in your methods to show messages:
$this->_messageManager->addError(__("Error Message"));
$this->_messageManager->addWarning(__("Warning"));
$this->_messageManager->addNotice(__("Notice"));
$this->_messageManager->addSuccess(__("Success Message"));
I hope this will help you fixing your issue.