Instantiate an object that takes a JPanel parameter using reflection

38 Views Asked by At

I'm trying to instantiate an object Robot knowing that the Robot constructor take a JPanel parameter using reflection.

Class<?> classRobot = null;
Constructor<?> constructorRobot;
classRobot = Class.forName(fullClassRobots.get(i));
constructorRobot = classRobot.getConstructor(JPanel.class);
robot.add((Robot)constructorRobot.newInstance(panelBattlefield));
public Robot(JPanel panelBattlefield) { 
...
}

My problem is that I keep getting a java.lang.NoSuchMethodException and I can't figure out what am I doing wrong.

0

There are 0 best solutions below