Syntax error: insert “enum Identifier”, insert “EnumBody”, inset “}”

▼魔方 西西 提交于 2021-02-18 11:57:05

问题


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?


回答1:


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...




回答2:


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




回答3:


Both the enum type and the class that you have just posted have two opening braces ({) and only one closing brace (}). If I had to guess, I'd say you need to put one more closing brace at the end of each of these files.



来源:https://stackoverflow.com/questions/9986398/syntax-error-insert-enum-identifier-insert-enumbody-inset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!