You could also get this error when JRE is not set. If so, try adding JRE System Library to your project.
Under Eclipse IDE:
- open menu Project --> Properties, or right-click on your project in Package Explorer and choose Properties (Alt+Enter on Windows, Command+I on Mac)
- click on Java Build Path then Libraries tab
- choose Modulepath or Classpath and press Add Library... button
- select JRE System Library then click Next
- keep Workspace default JRE selected (you can also take another option) and click Finish
- finally press Apply and Close.