Can not compile enums in Eclipse
Asked Answered
C

3

18

While trying to introduce enums in my Android project in Eclipse, I encountered with the following problem: Compiler says:

  1. The type java.lang.Enum cannot be resolved. It is indirectly referenced from required .class files
  2. The type Enum is not generic; it cannot be parameterized with arguments

I work under Ubuntu 10.04 and use Eclipse v.3.5.2. Tried to use both Java 6 OpenJDK and Java 6 Sun, but without success.

Can anybody help me to sort out with this issue?

Here is the code:

public class MyClass {

  public MyClass() {
  }

  ...

  enum MyEnum {
    CONST1, CONST2, CONST3;
  }
}
Crimple answered 28/9, 2010 at 8:38 Comment(1)
The code looks correct. The semicolon at the end is even optional.Didynamous
C
36

Open the properties for the project, select the page "Java Compiler" and set the "Compiler Compliance level" to "1.5" or better.

Project properties page for the Java Compiler

Contemptible answered 28/9, 2010 at 8:41 Comment(7)
Unfortunately I can't set "Compiler Compliance level" to "1.5" because I use @Override annotations for interfaces that is forbidden for 1.5Crimple
@Artem, @Override is allowed in JDK 1.5Mitchellmitchem
@Artem: If you can't set the compliance level to 1.5, you can't use enums because they are only allowed in Java 5.Contemptible
Thanks, Aaron, I thought if it's allowed in 1.5, then it's definitely allowed in 1.6. Please take a look: mindprod.com/jgloss/enum.htmlCrimple
Magic. Several times switched between 1.5 and 1.6 with full rebuild and now enums are compiled fine with 1.6.Crimple
@Artem: Sorry, I though it was clear that enums are allowed since Java 5 (which includes Java 6). Of course, they should work with Java 6 unless you have set the class or source compatibility to 1.4 or less.Contemptible
Thanks Aaron. it was definitely bug in Eclipse - probably because of other warning/errorsCrimple
P
3
  1. Go to properties of project with the build error (right click > Properties)
  2. View the "Libraries" tab in the "Build Path" section
  3. Find the "JRE System Library" in the list (if this is missing then this error message is not an eclipse bug but a mis-configured project)
  4. Remove the "JRE System Library"
  5. Hit "Add Library ...", Select "JRE System Library" and add the appropriate JRE for the project (eg. 'Workspace default JRE')
  6. Hit "Finish" in the library selection and "OK" in the project properties and then wait for the re-build of the project

Hopefully the error will be resolved ...

Prestissimo answered 23/4, 2013 at 9:55 Comment(0)
S
0

Close project the project with the error.

Open a different project and launch in emulator. Close the alternative project.

Open the original project with the error which should no longer be evidenced.

Don't know why it works or if actually launching the app is necessary but it clears the error .

Spongin answered 7/2, 2012 at 17:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.