Class c = Class.forName(newForm.getClass().getName()); Method method1 = c.getMethod("myMethod", parameterTypes); Object[] obj = new Object []{listOfStudents}; method1 .invoke((Object)c, obj);
Can someone tell me what this method invoke() takes as parameters? I am now giving the class that contains the method, and a list. (the method myMethod takes List as parameter) I am getting IllegalArgumentException on the method1.invoke line when i run this code currently
Have you read the API? It states that the first argument to invoke is "the object the underlying method is invoked from" or "If the underlying method is static, then the [first argument] may be null." Also, your first line can be more simply written:
I just realised that the method myMethod is in the superclass of the newForm class. I tried writing that line invoke(newForm, obj) and its still giving the same error. If it is there in the superclass, then wont i be able to access it??