I have
No enum constant [...] at java.lang.Enum.valueOf(Enum.java:238)
when I try to decode a single char string to an enum.
What is wrong, how can I fix it?
public class testEnum {
public enum Colors {
RED("R"), GREEN("G"), BLUE("B");
private final String code;
Colors(String code) {
this.code = code;
}
public String getCode() {
return code;
}
}
public static void main(String args[]) throws Exception {
Colors c = Colors.valueOf("R");
System.out.println(c);
}
}
In this case, I expect RED
to the ouput console.