我知道这个问题已经被问过很多次了,但是我真的还不明白为什么我要面对这个问题。博客和帖子中提供的答案已经在我的代码中实现,并且我仍然面临着这个问题(或者我仍然无法弄清为什么我的代码编译失败)
public class Utilities {
public Client client = null;
private static object x = null;
public Utilities(Client client) throws Exception {
this.client = client;
//CODE GOES HERE
}
}
我在其他文件中将此类称为
Utilities utile = new Utilities(client);
当我编译这段代码时,我遇到了错误,
constructor Utilities in class Utilities cannot be applied to given types
required: no arguments
found: Client
reason: actual and formal argument lists differ in length
在浏览了几个论坛帖子和博客之后,我添加了默认承包商,现在我的代码如下:
public class Utilities {
public Client client = null;
private static object x = null;
private Utilities() {
super();
// TODO Auto-generated constructor stub
}
public Utilities(Client client) throws Exception {
this.client = client;
//CODE GOES HERE
}
}
但是还是一样的错误。任何线索,我在这里做错了什么。
最佳答案
试试这个代码,让我知道:
public class Utilities {
private Client client;
private Object x;
//this is the normal structure of a constructor in java classes
public Utilities(Client client){
this.client = client;
//CODE GOES HERE
}
}