Java – enum valueOf IllegalArgumentException: No enum const class


I have used enums in java in the past but for some reason I am getting a strange error right now. the Line of code that it is throwing the error is:


I am getting a

java.lang.IllegalArgumentException: No enum const class

in the example line is an array of Strings.

I am just really confused right now, I do not know what could possibly be wrong.

Best Solution

The enum constants are case sensitive, so make sure you're constants are indeed lower case. Also, I would suggest that you trim() the input as well to make sure no leading / trailing white-space sneak in there:


For reference, here is a working sample program containing your line:

enum ConfigProperties { prop1, prop2 }

class Test {
    public static void main(String[] args) {

        String[] line = { "prop1" };

        switch (ConfigProperties.valueOf(line[0].toLowerCase())) {
        case prop1: System.out.println("Property 1"); break;
        case prop2: System.out.println("Property 2"); break;


Property 1