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:
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