I'm running the following and getting this error bellow. it seams to be a problem with invoke but I don't see anything that can cause it appreciate the help.
Class<?> eventClass;
long delayTime = restart.timeList.get(i);
try {
eventClass = Class.forName(restart.eventList.get(i));
Method runMethod = eventClass.getMethod("run");
//Method runMethod = eventClass.getDeclaredMethod("run");
//Object runEvent = runMethod.getParameterTypes();
System.out.println(runMethod.getName());
System.out.println(runMethod.getDeclaringClass());
runMethod.invoke(eventClass);
}
catch (ClassNotFoundException | NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
Output:
[com.COMP308.TME4.ThermostatNight, com.COMP308.TME4.LightOn, com.COMP308.TME4.WaterOff, com.COMP308.TME4.ThermostatDay, com.COMP308.TME4.Bell, com.COMP308.TME4.WaterOn, com.COMP308.TME4.LightOff, com.COMP308.TME4.Terminate, com.COMP308.TME4.FansOn, com.COMP308.TME4.FansOff]
run
class com.COMP308.TME4.ThermostatNight
Exception in thread "main" java.lang.IllegalArgumentException: object is not an instance of declaring class
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at com.COMP308.TME4.EventReflextion.main(EventReflextion.java:33)
Aucun commentaire:
Enregistrer un commentaire