What does the "Multiple markers" mean?
Solution 1
"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;
}
Solution 2
This means on a single line you are getting multiple errors.
The pic below describes the best. Refer @Jon Skeet to know how to resolve these errors.
.
Solution 3
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");
}
Roman
Updated on July 05, 2022Comments
-
Roman almost 2 years
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?
-
Roman over 13 yearsthank you for the answer. However, I do not understand it. What you mean by "insert statements directly into a class". What would be the correct syntax?
-
Jon Skeet over 13 years@Roman: Correct syntax for what? You just can't do what you were trying to do - statements can't be included directly in a class declaration; they have to be in initializers etc. That's why I've provided a method to create the set and populate it, and then called that method from the variable declaration.
-
Roman over 13 yearsthanks. Now I got what you mean. I could set values for static integer variable without usage of
private static
. And I just assumed that I can work with maps in the way I work with integers. But, because of some unknown to me reasons, I cannot. But it's OK. I just useprivate static
. Thanks. -
Jon Skeet over 13 years@Roman: No, it's nothing to do with integers in particular. It's not clear to me what you were doing before, but if you didn't have "static" on a variable declaration, then it wasn't a static variable...