To fix this error, first you need to completely remove the driver and associated software. To do this, go to Control Panel > Programs and Features> Uninstall a program and remove all HP associated software and drivers.
After this operation, run a copy of CCleaner and click on the Registry menu then clear the registry from obsolete entries.
Download the required drivers from the official website and install the package, then you will be able to use the printer.