title: Convert String to enum in Java
body: <p>I have defined this enum :</p>
  
  <pre><code>public enum UsageType {
  
      START("start"),
      PAUSE("pause"),
      RESUME("resume"),
      STOP("stop"),
      DESTROY("destroy");
  
      private final String mType;
  
      private UsageType(String type) {
          mType = type;
      }
  
      /**
       * Get the string representation of the UsageType
       * @return string representation of the UsageType
       */
      public String getAsText() {
          return mType;
      }
  }
  </code></pre>
  
  <p>In another class, I have a constractor that takes string, and I want to make an enum with that string:</p>
  
  <pre><code>public class AppUsage {
  
      private String mActivityName;
      private String mFormattedTime;
      private UsageType mUsageType;
  
      public AppUsage(String activityName, String formattedTime, String usageType) {
          mActivityName = activityName;
          mFormattedTime = formattedTime;
          mUsageType =  mUsageType.valueOf(usageType); //HERE STRING TO ENUM!
      }
  
      //Setters and Getters....
  </code></pre>
  
  <p>Here is the error I get:</p>
  
  <pre><code>java.lang.IllegalArgumentException: start is not a constant in com.embedonix.mobilehealth.serverwork.usage.UsageType
          at java.lang.Enum.valueOf(Enum.java:198)
          at com.embedonix.mobilehealth.serverwork.usage.UsageType.valueOf(UsageType.java:6)
  </code></pre>