When doing a method lookup using reflection you have to specify an array of
classes corresponding to the parameter types of the method.
Here is the skeleton of my code:
Class turtleClass = loader.findAndResolveClass(classname);
// just an empty array for now
Object[] arguments = new Object[] {new String[0]};
Class[] parameterTypes = new Class[] {arguments[0].getClass()};
try
{
// THIS CALL TO getMethod FAILS!!
Method mainMethod = turtleClass.getMethod("main", parameterTypes);
mainMethod.invoke(null, arguments);
}
catch (NoSuchMethodException e)
{
e.printStackTrace();
}
catch (InvocationTargetException e)
{
e.printStackTrace();
}
When executing the code I get the following exception:
java.lang.VerifyError: (class: Arcs, method: main signature:
([Ljava/lang/String;)V) Incompatible object argument for function call
at java.lang.Class.getMethod0(Native Method)
at java.lang.Class.getMethod(Class.java:883)
at com.otherwise.jurtle.Display.runTurtleCode(Display.java:114)
at
com.otherwise.jurtle.DisplayPane.runTurtleCode(DisplayPane.java:99)
The getMethod() call is failing with incompatible arguments. Anyone have any
thoughts as to the problem?
Replace the first line of your code with:
Object[] arguments = new String[0];
and you're there.
kenny