19

I am writing a simple Java program on Eclipse.

import java.util.HashMap;

public class Demo {
    public static void main(String[] args) {
        HashMap<String, String> hash = new HashMap();
    }
}

The above program generates the following errors.

  1. The project was not built since its build path is incomplete. Cannot find the class file for java.util.Map$Entry. Fix the build path then try building this project.
  2. The type java.util.Map$Entry cannot be resolved. It is indirectly referenced from required .class files.

I searched over the internet almost everywhere, but I was not able to correct this.

I have installed Java SE 8u5 (JDK) (http://www.oracle.com/technetwork/java/javase/downloads/index.html?ssSourceSiteId=otnjp)

  1. Windows -> Preferences -> Installed JREs shows

a) jdk C:\Program Files\Java\jdk

  1. Project -> Build Path -> Libraries shows

a) JRE system library (jdk)

b) JRE system library (jre8)

Please somebody help me.

EDIT: Changing Eclipse version from Helios to Juno solved the problem!

ashwin1907
  • 261
  • 1
  • 2
  • 6
  • Have you tried to restart eclipse? I had a similar error for `java.lang.Object` and restarting helped. – fabian Jun 08 '14 at 20:46
  • Yes, I tried restarting eclipse. I even restarted my laptop. It did not remove those errors. – ashwin1907 Jun 08 '14 at 20:53
  • 1
    Which version of Eclipse are you using? The release builds do not support Java 8 - you'll need a [patched version of Kepler](http://www.eclipse.org/downloads/index-java8.php) or a [Luna developer build](https://www.eclipse.org/downloads/index-developer.php). – McDowell Jun 08 '14 at 23:05
  • I am using Eclipse Helios. Will that be a problem? – ashwin1907 Jun 08 '14 at 23:27
  • 1
    Thanks McDowell, I changed Eclipse version to Juno, now it works! – ashwin1907 Jun 09 '14 at 00:24
  • I too had same issue with eclipse Indigo + java8. I tried to switch back to JDK 7 and suddenly it is fixed. :) – Raju Penumatsa Feb 14 '15 at 14:59
  • Updating the ecj.jar file to version ecj-4.4.2.jar worked for me – webber55 Aug 19 '15 at 11:31

1 Answers1

16

I've seen occasional problems with Eclipse forgetting that built-in classes (including Object and String) exist. The way I've resolved them is to:

  • On the Project menu, turn off "Build Automatically"
  • Quit and restart Eclipse
  • On the Project menu, choose "Clean…" and clean all projects
  • Turn "Build Automatically" back on and let it rebuild everything.

This seems to make Eclipse forget whatever incorrect cached information it had about the available classes.

Wyzard
  • 33,849
  • 3
  • 67
  • 87
  • 2
    I think that is more of that related to eclipse version. So if we can change version which is most supported by Java and Jre 8 that can be resolution of this issue. – Kishan Bheemajiyani Mar 28 '16 at 11:02
  • 4
    This happen also in Eclipse IBM RAD (Rational), with jdk8, the solution is using jdk7 – Enrique San Martín Nov 10 '17 at 16:57
  • @EnriqueSanMartín - You saved my day.. I knew that the problem was with JRE in RAD but I was keep on using different version of JRE8. Thanks for the tip. – tiktok Jan 22 '19 at 22:15
  • Thanks. Steps worked in 2020-12 version of Eclipse (jdk 11.0.8). – Ritesh Feb 01 '21 at 01:48