views:

81

answers:

1

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;
  }
}
+5  A: 

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

Aaron Digulla
Is this a workaround or a solution?
Bobby
It is a necessity.
Thilo
Unfortunately I can't set "Compiler Compliance level" to "1.5" because I use @Override annotations for interfaces that is forbidden for 1.5
Artem
@Artem, @Override is allowed in JDK 1.5
The Elite Gentleman
@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.
Aaron Digulla
Thanks, Aaron, I thought if it's allowed in 1.5, then it's definitely allowed in 1.6. Please take a look: http://mindprod.com/jgloss/enum.html
Artem
@Aaron Digulla: Source?
Jivings
Magic. Several times switched between 1.5 and 1.6 with full rebuild and now enums are compiled fine with 1.6.
Artem
@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.
Aaron Digulla
Thanks Aaron. it was definitely bug in Eclipse - probably because of other warning/errors
Artem