语法错误:插入“枚举标识符",插入"EnumBody",插入“}". [英] Syntax error: insert "enum Identifier", insert "EnumBody", inset "}"

查看:90
本文介绍了语法错误:插入“枚举标识符",插入"EnumBody",插入“}".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编码了一个枚举类型,当我为它运行创建的JUnit测试时会引发以下语法错误:

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

我的枚举类型具有静态函数,该函数针对特定的String返回枚举常量.这是我的一些枚举类型的代码:

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;
    }

}

我的其余静态函数非常相似(即is_letteris_octave等),尽管有些使用input.matches(regex)函数而不是检查输入是否等于特定字符串.

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.

这是JUnit测试的开始,该测试测试处理意外常量的功能:

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));
    }

}

我的JUnit测试中测试所有枚举静态函数的其他函数都以类似的方式编码.我不知道为什么会有这些语法错误(这是我第一次编码枚举类型).我一直在Eclipse中进行编码,到目前为止还没有发现任何缺少的}".我不知道这是否与编写测试的方式或声明变量的方式有关.有谁知道我为什么有这些语法错误?

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?

推荐答案

我在编写Android应用时遇到此错误.我所有的括号都关闭了;我从另一个站点跟踪一个示例.最后,我为代码选择了整个文本,然后剪切,保存并粘贴代码.错误消失了. Eclipse很可能卡住了...

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

这篇关于语法错误:插入“枚举标识符",插入"EnumBody",插入“}".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆