I get java.lang.NoSuchFieldException when I try to run the following method:
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); }
The error is on the line Time startTime = (Time)t.getClass().getField(day + "Start").get(t);
I do not understand this error, because monStart is a field of the Tutor class:
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;
I just learned how to use reflection, so I'm sure this is some kind of syntax error ...
java reflection
drew moore Mar 14 '13 at 21:56 2013-03-14 21:56
source share