I have defined this enum :
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;
}
}
In another class, I have a constractor that takes string, and I want to make an enum with that string:
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....
Here is the error I get:
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)