我java.lang.NoSuchFieldException
在尝试运行以下方法时遇到问题:
public void getTimes(String specialty, String day) {
ArrayList<Tutor> withSpec = new ArrayList<Tutor>();
for (Tutor t : tutorList){
try {
Time startTime = (Time)t.getClass().getField(day + "Start").get(t);
} catch (NoSuchFieldException | SecurityException | IllegalAccessException ex) Logger.getLogger(DBHandler.class.getName()).log(Level.SEVERE, null, ex); }
错误就在网上 Time startTime = (Time)t.getClass().getField(day + "Start").get(t);
我不明白此错误,因为monStart是Tutor
该类的字段:
Public class Tutor implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@NotNull
@Column(name = "tutorID")
private Integer tutorID;
....
@Column(name = "monStart")
@Temporal(TemporalType.TIME)
Date monStart;
我只是在学习使用反射,所以我确定这是某种语法错误...