我得到一个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;
我只是学习使用反射,所以我敢肯定这是某种形式的一个语法错误的...