enum frustration

C

Colin

I'm just starting to teach myself Java, and I'm having a terrible time
setting up a simple enum. I'm 99.9% sure the syntax is correct,
because I've checked it with numerous online tutorials, but I still
get errors. Here is my file:

Player.java:

package my.game;

public class Player {

public enum Controller {HUMAN, COMPUTER}

private String name;
private boolean isHuman; //I want to change this to be of type
Controller
private int money;
}

and my errors, all on the line with the enum, are

enum cannot be resolved to a type
Syntax error on token "~", ReferenceType expected (in Eclipse, this
error focuses on H in HUMAN)
Syntax error, insert ";" to complete BlockStatements
Syntax error, insert ";" to complete ClassBodyDeclarations

and the warning

'enum' should not be used as an identifier, since it is a reserved
keyword from source level 5.0 on


Thanks for you help,
Colin
 
O

Oliver Wong

Colin said:
I'm just starting to teach myself Java, and I'm having a terrible time
setting up a simple enum.

[snip. Error from Eclipse:]
'enum' should not be used as an identifier, since it is a reserved
keyword from source level 5.0 on

"enum" was introduced in Java 1.5 (AKA Java 5). Eclipse is telling you
that you need to set your project to target Java 5 or later if you want to
use it. Presumable, currently your project is targeting Java 1.4 or some
earlier version.

Right click on your project, choose "properties", select "Java
Compiler", set "Compiler compliance level" to "5.0" or some higher value
(e.g. 6.0 will work too).

That'll change your current project to use the new version. If you want
to change all projects to use the new version, click on the "Configure
Workspace Settings..." link to set the version for your entire workspace,
instead of only for individual projects.

- Oliver
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

illegal start of type 1
Enum Idiom Question 27
Another Compiler Error 2
Enum oddity 14
Enum question 0
Enum and code efficiency 4
enum type declaration error 6
Enum and the designer 0

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top