我想通过使用枚举类型的一个值作为输入来设置枚举类型:
这就是我使用的代码,
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
发布于 2011-05-31 06:02:44
试试这个:
public Item(String itemType) {
if (itemType == null) {
throw new IllegalArgumentException("null itemType");
}
this.itemType = Type.valueOf(itemType);
}https://stackoverflow.com/questions/6181054
复制相似问题