问题描述
|
我想通过使用其值之一作为输入来设置枚举类型:
这是我正在使用的代码,
package models;
import models.crudsiena.SienaSupport;
import siena.*;
public class Item extends SienaSupport {
@Id
public Long id;
public static enum Type{
A,B
};
public Type itemType;
public Item(String itemType) {
this.itemType = Type.valueOf(itemType);
}
}
当我尝试使用new Item(\"A\")
时,我会返回NullPointerException occured : Name is null
解决方法
尝试这个:
public Item(String itemType) {
if (itemType == null) {
throw new IllegalArgumentException(\"null itemType\");
}
this.itemType = Type.valueOf(itemType);
}