我想在Android的aplication,在这里我要检查一个整数等于一些枚举的价值。代码使用switch语句是这样的:Java的开关case语句问题
public enum RPCServerResponseCode{
E_INCORRECT_LOGIN(4001),
E_ACCOUNT_DISABLED(4002),
E_ACCOUNT_NOT_ACTIVE(4003);
private int value;
private RPCServerResponseCode(int i) {
this.value=i;
}
public static RPCServerResponseCode getByValue(int i) {
for(RPCServerResponseCode dt : RPCServerResponseCode.values()) {
if(dt.value == i) {
return dt;
}
}
throw new IllegalArgumentException("No datatype with " + i + " exists");
}
}
}
我的switch语句是这样的:
int errorCode;
switch(errorCode){
case RPCServerResponseCode.E_INCORRECT_LOGIN :
{
if (user.isAuthenticated)
{
// logout before login
}
break;
}
case RPCServerResponseCode.E_ACCOUNT_NOT_ACTIVE:
{
if (user.isAuthenticated)
{
//logout
}
break;
}
}
}
,但我得到错误说的:“类型不匹配:不能从RPCCommucatorDefines.RPCServerResponseCode转换为int”。 任何建议如何解决这个问题?提前致谢!!!
的可能重复[switch语句:数枚举值/ 1002 = MyEnum.NewYorkID](http://stackoverflow.com/questions/7162192/switch-statement-number-to-enum-value-1002-myenum-newyorkid) –
感谢您的评论。其实我没有看到这个问题。 –