public enum AlaTyp implements EnumClass<Integer> {
OVERRUN(1),
TREND(2);
private final Integer id;
AlaTyp(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
@Nullable
public static AlaTyp fromId(Integer id) {
for (AlaTyp at : AlaTyp.values()) {
if (at.getId().equals(id)) {
return at;
}
}
return null;
}
}
public class HandleScreen extends Screen {
@Autowired
private TextField<AlaTyp> alaTypField;
private List<AlaRec> list;
public void setList(List<AlaRec> list) {
this.list = list;
}
@Subscribe
public void onBeforeShow(BeforeShowEvent event) {
if (list.size()==1){
for (AlaRec alaRec:list
) {
alaTypField.setValue(alaRec.getAlaTyp());
}
} else {
alaTypField.setVisible(false);
}
}
报错信息:
Caused by: java.lang.reflect.InvocationTargetException: null
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:153) ~[vaadin-server-8.14.3-0-jmix.jar:8.14.3-0-jmix]
... 90 common frames omitted
Caused by: java.lang.ClassCastException: class cn.edu.hitwh.ef.hm.pm.enm.AlaTyp cannot be cast to class java.lang.String (cn.edu.hitwh.ef.hm.pm.enm.AlaTyp is in unnamed module of loader 'app'; java.lang.String is in module java.base of loader 'bootstrap')