Salve,
ho un problema con la reflection di java. Il mio codice:
Class cls = entities.get(i).getClass();
Class[] parametertype = new Class[] {String.class};
Method m;
try {
m = cls.getMethod("setNome", parametertype);
Object res = m.invoke(cls, sorgenteNome);
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException | IllegalArgumentException
| InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Entities, contiene oggetti istanziati e valorizzati.
Il problema è che mi si verifica l'eccezione :
IllegalArgumentException: object is not an instance of declaring class
non riesco a capire dove sia l'errore, visto che il metodo che chiamo è corretto e la sua firma
è un parametro solo ed è una stringa.
Qualcuno mi può dare una indicazione?
Grazie
Alan.