0

我正面临这个错误

groovy.lang.GroovyRuntimeException:找不到匹配的构造函数:AnimalInfoType(java.lang.String,java.lang.Integer,java.lang.Integer)时

通过“run-app”启动应用程序,我为 Enum 创建了构造函数,如下所示:

    package jogoanimais

    public enum AnimalInfoType
    {
      ANIMAL(1), 
      ACTION(2)

        final int value
        private AnimalInfoType(int value) {
          this.value = value
        }

        int value() { value }    
    }

我的域类是这样的:

    class AnimaisTreeMap {

       String nodeDescription
       AnimalInfoType nodeInfo
       AnimaisTreeMap yesAnswerNode
       AnimaisTreeMap noAnswerNode

        static constraints = {
            yesAnswerNode nullable:true
            noAnswerNode nullable:true        

        }
        static mappedBy = [ yesAnswerNode: "none", noAnswerNode: "none" ]   
        static mapping = {
            yesAnswerNode cascade: 'delete'
            noAnswerNode cascade: 'delete'
        }
    }

在我的 BootStrap.groovy 中,我像这样填写表格:

    def noAnswer =  new AnimaisTreeMap(nodeDescription:"macaco", 
                                       nodeInfo: AnimalInfoType.ANIMAL,
                                       noAnswerNode:null, 
                                       yesAnswerNode:null)
    noAnswer.save(failOnError: true)
    def yesAnswer =  new AnimaisTreeMap(nodeDescription:"tubarão", 
                                        nodeInfo: AnimalInfoType.ANIMAL,
                                        noAnswerNode:null, 
                                        yesAnswerNode:null)
    yesAnswer.save(failOnError: true)           

    new AnimaisTreeMap(nodeDescription:"vive na água", 
                       nodeInfo: AnimalInfoType.ACTION,
                       noAnswerNode: noAnswer, 
                       yesAnswerNode:  yesAnswer).
                       save(failOnError: true)                  
}

我在 BootStrap.groovy 做错了什么?

4

2 回答 2

1

删除枚举构造函数及其公共定义。没必要,默认情况下所有类都是公共的。

并编辑以 Enum 结尾的类。动物信息类型枚举。

enum AnimalInfoTypeEnum
{
  ANIMAL(1), 
  ACTION(2)

    final int value

    int value() { value }    
}
于 2015-12-17T22:17:51.413 回答
0

也许试试这个:

package jogoanimais

enum AnimalInfoType{
   ANIMAL(1), 
   ACTION(2)

   private final int value

   private AnimalInfoType(int value) {
      this.value = value
   }

   int value() { value }
}

不让我评论,没有足够的代表。

于 2015-12-17T18:42:35.040 回答