8

I have an Enum in Java and each of its enumeration members have a number of parameters. What I am trying to do is make one of these parameters as an array of Strings but I can't seem to be able to make the correct initialization.

Here's what I've tried:

private static enum DialogType {
    ACCCAT("Acccat", new String[] {"acccatid"}, "acccatText", "dlg7Matchcode", "Zutritts\nkategorie", "Text"),

    private String mDialogName;
    private String[] mKeyField;
    private String mTextField;
    private String mSelectFields;
    private String mKeyFieldHeader;
    private String mTextFieldHeader;

    private DialogType(String dialogName, String[] keyField, String textField, String selectFields, String keyFieldHeader, String textFieldHeader) {
        mDialogName = dialogName;
        mKeyField = keyField;
        mTextField = textField;
        mSelectFields = selectFields;
        mKeyFieldHeader = keyFieldHeader;
        mTextFieldHeader = textFieldHeader;
    }
}

However, I am getting a ton of syntactic errors. Any ideas?

3 Answers 3

14

Make that

public  enum DialogType {
    ACCCAT("Acccat", new String[] {"acccatid"}, "acccatText", 
           "dlg7Matchcode", "Zutritts\nkategorie", "Text");

And it should work. Note the ; at the end of the ACCAT. Also the enum can't be static.

Sign up to request clarification or add additional context in comments.

1 Comment

Ah, stupid me, problem wasn't even related to my array. And my enum is internal to a JUnit test class so I don't think static is a problem. Although it might not make much sense.
2

This should do the trick - Semicolon at the end of the ACCCAT line

private static enum DialogType {

    ACCCAT("Acccat", new String[]{"acccatid"}, "acccatText", "dlg7Matchcode", "Zutritts\nkategorie", "Text");
    private String mDialogName;
    private String[] mKeyField;
    private String mTextField;
    private String mSelectFields;
    private String mKeyFieldHeader;
    private String mTextFieldHeader;

    private DialogType(String dialogName, String[] keyField, String textField, String selectFields, String keyFieldHeader, String textFieldHeader) {
        mDialogName = dialogName;
        mKeyField = keyField;
        mTextField = textField;
        mSelectFields = selectFields;
        mKeyFieldHeader = keyFieldHeader;
        mTextFieldHeader = textFieldHeader;
    }
}

Comments

1
ACCCAT("Acccat", new String[] {"acccatid"}, "acccatText", "dlg7Matchcode", "Zutritts\nkategorie", "Text");

I think you just want a semi-colon at the end of the instance declaration.

I presume the enum is static because it's an inner enum of something?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.