I have class Errors.
I have value errorCode.
I need get string by errorCode.
example, int number = -2;
Errors.Parse(number).toString();
return value #-2#The username is already in use.
public enum Errors {
UNKNOWN_ERROR(-1, "Unknown error"),
LOGIN_ALREADY_EXISTS(-2, "The username is already in use."),
LOGIN_OR_PASSWORD_NOT_CORRECT (-3, "LOGIN_OR_PASSWORD_NOT_CORRECT"),
NULL_POINTER (-4,"Null pointer exception"),
NOT_CORRECT_DATA (-5,"NOT_CORRECT_DATA");
private final int errorCode;
private final String message;
private Errors(int errorCode, String message) {
this.errorCode = errorCode;
this.message = message;
}
public int getErrorCode() {
return errorCode;
}
public String getMessage() {
return message;
}
@Override
public String toString() {
return "#" + errorCode + "#" + message;
}
}
You will have to loop the values of your enum and check individually the error code of each against the given error code (num).
something like: