tags:

views:

46

answers:

1

Hello,

i want to use Enum to represent some selection values. In /src/groovy folder, under the package com.test, I created the Enum.

package com.test

public  enum TabSelectorEnum {
  A(1), B(2)

  private final int value
  public int value() {return value}

}

Now, I am trying to access it from controller like

TabSelectorEnum.B.value()

It throws an exception

Caused by: org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.NoClassDefFoundError: Could not initialize class com.test.TabSelectorEnum

thanks in advance.

Update: I cleaned and recompiled . the error code changed to

groovy.lang.GroovyRuntimeException: Could not find matching constructor for: com.test.TabSelectorEnum(java.lang.String, java.lang.Integer, java.lang.Integer)

seems like something wrong in the way accessing the value of enum !!

+2  A: 

You didn't define a constructor for the int value:

package com.test

enum TabSelectorEnum {
   A(1),
   B(2)

   private final int value

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

   int value() { value }
}
Burt Beckwith
Burt, thanks you so much.
bsreekanth