From what I understand, this error occurs when installing Java if older versions are already installed.
To fix it, just remove old versions through the “Programs and Features” section in the “Control Panel”. Reboot the computer and try to install again.
But in my case, it was not possible to manually remove old versions. Therefore, let’s move on to a more complex method, which will certainly help 🙂
Method 1: try to remove old versions through the official Java utility
Very easy: https://www.java.com/en/download/uninstalltool.jsp
Download application, launch it, remove old versions. Restart PC. Try to install JRE/JSK again. In my case this app even not started. I don’t know why. So if in your case too, let’s go to method 2
Method 2: uninstall old versions of Java using Windows Utility
Let’s launch. Step by step we remove each old version of Java. This takes a long time, so we don’t worry.
After this restart PC. Install JDK/JRE again and it will be ok 🙂 After this, check your variables
In this dirs should be new version of Java. Also check JRE home too ( install it if need). Restart PC and we done 🙂