我知道这个问题被问了很多次,但我真的不明白我为什么要面对这个问题。博客和帖子中提供的答案已在我的代码中实现,我仍然面临这个问题(或者我仍然无法弄清楚为什么我的代码编译失败)
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
}
}
但仍然是同样的错误。任何线索我在这里做错了什么。
答案 0 :(得分:0)
试试这段代码并告诉我:
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
}
}