I use the enumeration with the switch case, but I get the following error:
FEED NEWS is not a constant in FragmentName
This is the string constant enum,
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; } }
When i call
changeTitle("NEWS FEED");
it throws an exception in the changeTitle function, even the passed value is the same, so any help would be appreciated as I tried my best to solve this problem.
source share