Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2007

Tip: Looking for answers? Try searching our database.

enum frustration

Thread view: 
Colin - 19 Feb 2007 22:21 GMT
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
Oliver Wong - 19 Feb 2007 22:33 GMT
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.