我确实在这一行中遇到了这个错误。请帮帮我。
public enum **Status**
{
CLASS_NOT_FOUND_EXCEPTION = new Status("CLASS_NOT_FOUND_EXCEPTION", 2);
ILLEGAL_ACCESS_EXCEPTION = new Status("ILLEGAL_ACCESS_EXCEPTION", 3);
INSTANTIATION_EXCEPTION = new Status("INSTANTIATION_EXCEPTION", 4);
MALFORMED_URL_EXCEPTION = new Status("MALFORMED_URL_EXCEPTION", 5);
IO_EXCEPTION = new Status("IO_EXCEPTION", 6);
INVALID_ACTION = new Status("INVALID_ACTION", 7);
JSON_EXCEPTION = new Status("JSON_EXCEPTION", 8);
ERROR = new Status("ERROR", 9);
Status[] arrayOfStatus = new Status[10];
arrayOfStatus[0] = NO_RESULT;
arrayOfStatus[1] = OK;
arrayOfStatus[2] = CLASS_NOT_FOUND_EXCEPTION;
arrayOfStatus[3] = ILLEGAL_ACCESS_EXCEPTION;
arrayOfStatus[4] = INSTANTIATION_EXCEPTION;
arrayOfStatus[5] = MALFORMED_URL_EXCEPTION;
arrayOfStatus[6] = IO_EXCEPTION;
arrayOfStatus[7] = INVALID_ACTION;
arrayOfStatus[8] = JSON_EXCEPTION;
arrayOfStatus[9] = ERROR;
$VALUES = arrayOfStatus;
}
答案 0 :(得分:0)
如您所知,Java中的枚举是作为一个具有预定义值列表的类实现的,因此它可能(在您的情况下必须)包含字段和构造函数(当然还包括方法)。
所以这里有类似于你的尝试和有效的Java Enum
enum Status {
CLASS_NOT_FOUND_EXCEPTION("CLASS_NOT_FOUND_EXCEPTION", 2),
ILLEGAL_ACCESS_EXCEPTION("ILLEGAL_ACCESS_EXCEPTION", 3),
INSTANTIATION_EXCEPTION("INSTANTIATION_EXCEPTION", 4),
MALFORMED_URL_EXCEPTION("MALFORMED_URL_EXCEPTION", 5),
IO_EXCEPTION("IO_EXCEPTION", 6),
INVALID_ACTION("INVALID_ACTION", 7),
JSON_EXCEPTION("JSON_EXCEPTION", 8),
ERROR("ERROR", 9);
private String title;
private int number;
private Status(String title, int number) {
this.title = title;
this.number = number;
}
// getters
}
在此定义之后,如果您确实需要,可以创建Enum值数组。