Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the "Multiple markers" mean?

I am trying to use sets in the following way:

static Set<String> languages = new HashSet<String>();
languages.add("en");
languages.add("de");

And I get the following error message generated by Eclipse:

> Multiple markers at this line
>   - Syntax error on token ""en"", delete this      token
>   - Syntax error on token(s), misplaced    construct(s)

I cannot figure out what I am doing wrong. Can anybody please help me?

like image 926
Roman Avatar asked Feb 14 '11 11:02

Roman


2 Answers

"Multiple markers" just means "there's more than one thing wrong with this line".

But the basic problem is that you're trying to insert statements directly into a class, rather than having them in a constructor, method, initializer etc.

I suggest you change your code to something like this:

static Set<String> languages = getDefaultLanguages();

private static Set<String> getDefaultLanguages()
{
    Set<String> ret = new HashSet<String>();
    ret.add("en");
    ret.add("de");
    return ret;
}
like image 87
Jon Skeet Avatar answered Sep 20 '22 15:09

Jon Skeet


You are doing something illegal:

Either this (if your code is at class level):

// field definition on class level
static Set<String> languages = new HashSet<String>();
// statements are not allowed here, the following lines are illegal:
languages.add("en");
languages.add("de");

or this:

private void foo(){
    // static keyword not legal inside methods
    static Set<String> languages = new HashSet<String>();
    languages.add("en");
    languages.add("de");

}

Instead, you could use a static initializer to initialize your set:

static Set<String> languages = new HashSet<String>();
static{
  languages.add("en");
  languages.add("de");
}
like image 20
Sean Patrick Floyd Avatar answered Sep 23 '22 15:09

Sean Patrick Floyd