我使用切换案例枚举,但我收到以下错误:
NEWS FEED is not a constant in FragmentName
这是我的枚举字符串常量,
public enum FragmentName{
FRAGMENT_NEWSFEED("NEWS FEED"),
FRAGMENT_MESSAGES("MESSAGES"),
FRAGMENT_EVENTS("EVENTS"),
FRAGMENT_WHOISAROUDNME("WHOS AROUND");
private final String text;
private FragmentName(final String text) {
this.text = text;
}
@Override
public String toString() {
return text;
}
}
//This is my function from where i check for corresponding enum constant
public void changeTitle(String title) {
switch (Enums_String.FragmentName.valueOf(title)) {
case FRAGMENT_NEWSFEED:
System.out.println("1");
break;
case FRAGMENT_EVENTS:
System.out.println("2");
break;
case FRAGMENT_MESSAGES:
System.out.println("3");
break;
case FRAGMENT_WHOISAROUDNME:
System.out.println("4");
break;
}
}
我打电话的时候
changeTitle("NEWS FEED");
它会在changeTitle函数中创建一个异常,即使传递的值是相同的,所以任何帮助都会受到赞赏,因为我已尽力解决这个问题.