Legend legend = ApplicationContext.getLegend();
TreePath[] treePath = getTreePath();
Method method = legend.getClass().getDeclaredMethod("getItems", TreePath[].class);
method.setAccessible(true);
method.invoke(legend, treePath);
In Legend.class:
private List<LegendItem> getItems(TreePath[] treePath) {
List<LegendItem> items = new ArrayList();
if (treepath == null) {
return items;
}
for (int i = 0; i < treepath.length; i++) {
Object[] ob = treepath[i].getPath();
DefaultMutableTreeNode node = (DefaultMutableTreeNode)ob[(treepath[i].getPathCount() - 1)];
}
items.add((LegendItem)node.getUserObject());
return items;
}
Why do I get
Java.lang.IllegalArgumentException: argument type mismatch
when I execute? I defined the parameter to be TreePath[]
and the parameter I pass is of that type?!
And also following Warning:
Type TreePath[] of the last argument to method invoke(Object, Object...) doesn't exactly match the vararg parameter type. Cast to Object[] to confirm the non-varargs invocation, or pass individual arguments of type Object for a varargs invocation.
for method.invoke(legend, treePath)
Solved:
method.invoke(legend, new Object[] {treePath});