I’m trying to work with an app that’s been built in Grails, but I’m getting an error I don’t understand. Basically, I’ve got an enum:
package com.wbr.manning.common
public enum ChapterType {
CHAPTER("chapter"), PREFACE("preface"), APPENDIX("appendix"), PART("part")
ChapterType(String value) { this.value = value }
String value
String getKey() { name() }
String toString() { value }
}
But when I try to list the Chapter objects, I get:
java.lang.IllegalArgumentException: No enum const class com.wbr.manning.common.ChapterType.part
at java.lang.Enum.valueOf(Enum.java:196)
at grails.orm.HibernateCriteriaBuilder.invokeMethod(HibernateCriteriaBuilder.java:1163)
at com.wbr.manning.agileAuthor.AAChapterController$_closure3.doCall(AAChapterController.groovy:39)
at com.wbr.manning.agileAuthor.AAChapterController$_closure3.doCall(AAChapterController.groovy)
at java.lang.Thread.run(Thread.java:662)
2012-04-02 09:55:23,401 [http-8080-1] ERROR common.ErrorsController - org.codehaus.groovy.grails.web.errors.GrailsWrappedRuntimeException: No enum const class com.wbr.manning.common.ChapterType.part
Any ideas on what I’m doing wrong here? Do I have the enum correct, or do I need to look at the calling code?
Thanks!
If you want to lookup the Enum based on it’s value, you need to add a static method to your enum like so:
You can then do: