Jump to content

View more

Image of the Day

雑魚は多めにして、爽快感重視にしつつ・・・(´・ω・`)
早いとこ、ベースを作って、完成にもっていかないとね。
タイトルもまだ迷ってるだよなぁ。 
#indiedev  #indiegame #screenshotsaturday https://t.co/IwVbswGrhe
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

trouble making an enum in java (weird error(s))

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
4 replies to this topic

#1 Enerjak   Members   

277
Like
0Likes
Like

Posted 30 October 2012 - 08:53 AM

as you can tell from the title, i'm having a little trouble currently creating an enum in java as it gives weird errors such as:

http://puu.sh/1kuOn

not sure if you want the code also as it's right there in the image let me know.

#2 rip-off   Moderators   

10891
Like
1Likes
Like

Posted 30 October 2012 - 09:16 AM

Please post the code. If you want to add fields, constructors or methods to a Java enumeration, you must end the list of enum names with a semicolon:
public enum Suit {
    Hearts,
    Spades,
    Clubs,
    Diamonds; // <-- Semicolon here indicates end of suits!

    @Override
    public String toString() {
        // ...
    }
}


#3 Enerjak   Members   

277
Like
0Likes
Like

Posted 30 October 2012 - 09:24 AM


/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

package javaapplication1;

/**

*

* @author lucifir

*/

public class JavaApplication1 {

    enum Suit

    {

	    private final String colName;

	   

	    private Suit(String name)

	    {

		    colName = name;

	    }

    }

    /**

	 * @param args the command line arguments

	 */

    public static void main(String[] args) {

	    // TODO code application logic here

    }

}



#4 ppgamedev   Members   

311
Like
1Likes
Like

Posted 30 October 2012 - 09:45 AM

[source lang="java"]package javaapplication1;public class JavaApplication1 { enum Suit { HEARTS("Hearts"), SPADES("Spades"), CLUBS("Clubs"), DIAMONDS("Diamonds"); private final String colName; private Suit(String name) { colName = name; } } public static void main(String[] args) { // TODO code application logic here }}[/source]

Edited by ppgamedev, 30 October 2012 - 09:45 AM.


#5 Enerjak   Members   

277
Like
0Likes
Like

Posted 30 October 2012 - 10:01 AM

thanks alot.




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.