When I enter a string that it not in the list, I get this error in my enum CrimeType
class: IllegalArgumentException, no enum const class CrimeType.a(in java.lang.Enum
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();
}
Enum Class
public enum CrimeType
{
murder, arson, assault, fraud, theft, vandalism, drunk, littering, badHair;
}
Crimes Class
import java.util.*;
import java.text.*;
public class Crimes
{
private LinkedList<CrimeType> crimes = new LinkedList<CrimeType>();
public Crimes()
{
}
public void add(String crime)
{
CrimeType newCrime = CrimeType.valueOf(crime);
crimes.add(newCrime);
}
}