Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax error: insert "enum Identifier", insert "EnumBody", inset "}"

I coded an enum type which brings up the following Syntax errors when I run my created JUnit test for it:

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 which for a particular String, returns an enum constant. Here is some of my code of the enum type:

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 input.matches(regex) function instead of checking to see if an input it equals a particular string.

Here is the beginning of the JUnit test which tests the function dealing with the accidental 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 which test all the enum static functions are coded similarly. I cannot figure out why I have these syntax errors (this is my first time coding an enum type). I've been coding in Eclipse and have not found any missing "}"s as of yet. I don't know if this has anything to do with the way I've written the test or the way I've declared my variables. Does anyone know why I have these syntax errors?

like image 533
tkrishnan Avatar asked Apr 03 '12 02:04

tkrishnan


2 Answers

I had this same problem with Eclipse. The wrong syntax error message was due to a misplaced ";" after an annotation.

like image 139
neves Avatar answered Oct 16 '22 23:10

neves


I was getting this error while writing an Android app. All my brackets were closed; I was following an example from a different site. I ended up selecting the entire text for my code, cutting, saving, and pasting the code back. The error went away. It's very possible that Eclipse got stuck...

like image 3
wileyCoyote Avatar answered Oct 16 '22 22:10

wileyCoyote