我正在制作一款新游戏,遇到了一个问题。当我编译时,终端显示:
./Button.java:29: error: constructor Rect in class Rect cannot be applied to given types;
public Button(int x0, int y0, int x1, int y1) {
^
required: int,int,int,int
found: no arguments
reason: actual and formal argument lists differ in length
1 error
我真的不确定发生了什么。正如你所看到的,上面写着found: no arguments
但它也表示CCD_ 2。它似乎自相矛盾。。。我注意到,当我将"按钮"从"Rect"中拉出时,这种情况就开始发生了
请帮忙。
从错误消息中,可以看出Rect
类有一个四参数构造函数,而它没有一个无参数构造函数。
子类构造函数必须调用超类构造函数。如果您没有显式调用一个,那么Java将插入一个对默认无arg构造函数的隐式调用。这就是失败的地方。Rect
中没有arg构造函数。
这里必须显式调用超类构造函数,因为Rect
中没有可用的arg构造函数。
public Button(int x0, int y0, int x1, int y1) {
super(x0, y0, x1, y1);
// Rest of your constructor here
}