I am attempting to write a method the executes a static method from another class by passing an array of strings as arguments to the method.
Here\'s what I have:
The method your trying to invoke is expecting String array, however you are passing Object array as param. Change it to String array Or you can pass any type if the method expects Object.
method.invoke(null,(Object) command );
Based on this question, it looks like the call should be
method.invoke(null, command);
You have two problems:
String[]
, but you're passing in a Object[]
The problems are all in the inner try
block, so I show only that code.
String[] args = Arrays.copyOfRange(command, 1, command.length - 1);
method.invoke(null, new Object[]{args}); // must prevent expansion into varargs
Thanks to Perception for reminding me of the varargs issue