1
Je reçois un IllegalArgumentException
, mais je n'arrive pas à comprendre pourquoi.Java: exception d'argument illégale
La fonction que je suis en train d'accéder:
private static Player checkEvents(Player[] players, GameMaster bananas)
Le code problématique:
@Test
public void testCheckEvents() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
Game g = new Game();
GameMaster gm = new GameMaster(4);
Player[] p = new Player[] {new Player(gm), new Player(gm), new Player(gm), new Player(gm)};
Method checkEvents = g.getClass().getDeclaredMethod("checkEvents", new Class[] {p.getClass(), GameMaster.class});
checkEvents.setAccessible(true);
checkEvents.invoke(p, gm); // fails here
}
L'échec:
testCheckEvents(nth.bananas.GameTest)
java.lang.IllegalArgumentException: wrong number of arguments
Qu'est-ce que je fais mal?
Pour développer la réponse correcte de @ hjhill, si l'objet Method fait référence à une méthode statique, le premier argument de invoke() est ignoré. –