<class> 类中的构造函数<class>不能应用于给定类型



我正在制作一款新游戏,遇到了一个问题。当我编译时,终端显示:

./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
}

相关内容

最新更新