Note that there are some explanatory texts on larger screens.

plurals
  1. POIllegal argument exception
    text
    copied!<p>When I enter a string that it not in the list, I get this error in my enum CrimeType </p> <pre><code>class: IllegalArgumentException, no enum const class CrimeType.a(in java.lang.Enum). </code></pre> <p>What does it mean and how can I fix this?</p> <pre><code>public void enterCrime() { Crimes crimes = new Crimes(); System.out.print("\t\tEnter crime: "); crimeName = In.nextLine(); if("murder".equals(crimeName) || "arson".equals(crimeName) || "assault".equals(crimeName)) { crimes.daysToStay(3); } else if("fraud".equals(crimeName) || "theft".equals(crimeName) || "vandalism".equals(crimeName)) { crimes.daysToStay(2); } else if("drunk".equals(crimeName) || "littering".equals(crimeName) || "badHair".equals(crimeName)) { crimes.daysToStay(1); } else { System.out.println("\t\tThat is not a valid crime. The crimes are"); crimes.list(); } crimes.add(crimeName); enterAction(); } </code></pre> <p>Enum Class</p> <pre><code>public enum CrimeType { murder, arson, assault, fraud, theft, vandalism, drunk, littering, badHair; } </code></pre> <p>Crimes Class</p> <pre><code>import java.util.*; import java.text.*; public class Crimes { private LinkedList&lt;CrimeType&gt; crimes = new LinkedList&lt;CrimeType&gt;(); public Crimes() { } public void add(String crime) { CrimeType newCrime = CrimeType.valueOf(crime); crimes.add(newCrime); } </code></pre> <p>Ok, i've changed it to .equals now, which fixes the first problem, but when I enter something else, I still get that error in the enum class.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload