0

My enum file looks like this:

My application class basically asks users to enter a genre and then uses an instance to add objects inside an arraylist. Following is the part of code which asks the users to enter the genre and then add:

However every time after I run the application and the 'Enter Genre' shows up in the console, the following errors are printed before I can even type in the enum.

Exception in thread "main" java.lang.IllegalArgumentException: No enum constant part01.Genre.
    at java.base/java.lang.Enum.valueOf(Enum.java:273)
    at part01.Genre.valueOf(Genre.java:3)

I used the code without using toUpperCase earlier but still had the same errors. I'm really having a hard time figuring out why is this error being caused.

Can someone guide me about this?

  • Please show the code in between where you declare `Scanner input` (I guess it's a `Scanner`?) and the `input.nextLine()` you show. – Andy Turner Mar 19 '21 at 20:32
  • I suspect it's a duplicate of [this](https://stackoverflow.com/questions/13102045/scanner-is-skipping-nextline-after-using-next-or-nextfoo). – Andy Turner Mar 19 '21 at 20:33
  • I declared Scanner input as a a static global variable in the class and been using the same scanner for different inputs @AndyTurner – John Carlson Mar 19 '21 at 20:53
  • https://stackoverflow.com/questions/13102045/scanner-is-skipping-nextline-after-using-next-or-nextfoo - Helped with this. – John Carlson Mar 19 '21 at 21:03

0 Answers0