How to resolve Joomla Fatal Error

I faced the below Fatal error when I tried to access my website after restoring it from previous backup (files/folders were deleted by mistake). Similar Fatal error showed up when I tried to login to site as administrator-

——————————————————————————————————————————–

Fatal error: JApplicationCms::getUserState(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition “Joomla\Registry\Registry” of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in /libraries/cms/application/cms.php on line 504

or

Fatal error: JUser::getParam(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition “Joomla\Registry\Registry” of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in /libraries/joomla/user/user.php on line 286

——————————————————————————————————————————

The problem was caused due to active session (not closed properly) in the Joomla! sessions table.

Follow below steps to resolve these errors:

1. Login to cPanel.
2. Access the DB using PhPmyAdmin.
3. Delete all the user sessions from the sessions table.

Now website is accessible without any errors.