Syntax error: insert "enum Identifier", insert "EnumBody", inset "}"
I have coded an enum type that throws the following syntax errors when running my generated JUnit test:
java.lang.Error: Unresolved compilation problems:
Syntax error, insert "enum Identifier" to complete EnumHeaderName
Syntax error, insert "EnumBody" to complete EnumDeclaration
Syntax error, insert "}" to complete ClassBody
My enum type has static functions that return an enum constant for a particular string. Here are some of my enum type code:
public enum MusicType {
ACCIDENTAL, LETTER, OCTAVE, REST, DUR, CHORD, TUPLET;
public static MusicType is_accidental(String a){
if (a=="^" | a=="_"|a=="=")
return ACCIDENTAL;
else return null;
}
}
The rest of my static functions are very similar (i.e. is_letter
, is_octave
etc.), although some use a function input.matches(regex)
instead of checking to see if an input matches a particular string.
Here is the start of a JUnit test that tests the function associated with a random constant:
public class MusicTypeTest {
@Test
public void accidentalTest(){
String sharp = "^";
String flat = "_";
String natural = "=";
assertEquals(MusicType.ACCIDENTAL, MusicType.is_accidental(sharp));
assertEquals(MusicType.ACCIDENTAL, MusicType.is_accidental(flat));
assertEquals(MusicType.ACCIDENTAL, MusicType.is_accidental(natural));
}
}
The other functions in my JUnit test that test all static enum functions are coded in a similar way. I can't figure out why I have these syntax errors (this is my first time coding for an enum type). I have been coding in Eclipse and have not found any missing "yet."
I was getting this error while writing an android app. All of my parentheses were closed; I followed an example from another site. In the end, I selected all the text for my code, cut, saved and pasted the code back. The error is gone. It is very possible that Eclipse is stuck ...
Both enum types and the class you just posted have two opening braces ( {
) and only one closing shape ( }
). If I had to guess, I would say that you need to add another closing parenthesis at the end of each of these files.
I had the same problem with Eclipse. Wrong syntax error message was caused by wrong ";" after annotation.