我正在尝试将我的 JFrame 窗口的形状设置为椭圆,但它却抛出了以下错误:
java.lang.IllegalArgumentException: wrong number of arguments
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at Splash.setShape(Splash.java:48)
at Splash.<init>(Splash.java:25)
at BackOffice.init(BackOffice.java:40)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
问题是我正在发送 2 个参数,而该方法只接受 2 个参数,所以我看不到我从哪里得到这个错误?错误指向的行是mSetWindowShape.invoke(this, shape);
这里所说的行是相关方法:
private void setShape() {
Class<?> awtUtilitiesClass;
try {
awtUtilitiesClass = Class.forName("com.sun.awt.AWTUtilities");
Method mSetWindowShape = awtUtilitiesClass.getMethod("setWindowShape", Window.class, Shape.class);
Shape shape = (Shape) new Ellipse2D.Double(0, 0, getWidth(), getHeight());
mSetWindowShape.invoke(this, shape);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
编辑:我取消了一个参数并得到了同样的错误(参数数量错误)。然后我输入 3 个参数(窗口、形状、0)并得到“参数类型不匹配”。然后我尝试了一个布尔值和一个字符串作为第三个参数,但它们也给出了“参数类型不匹配”。我不明白这一点,因为在教程中它只显示了 2 个参数。现在显然有三个?