Suppose if your JRE is not defined properly, you might get this error.
Just follow the below steps to solve this error.
In Eclipse:
1.Right click on your project (Package Explorer mode) and select Build Path -> Configure Build Path
2.Go to Libraries tab
3.Click Add Library.
4.Select JRE System Library
5.Click Next
6.Select your JRE
7.Click Finish.
Once finish, make a clean and build.