2

我知道这个问题已经被问过很多次了,但我还是不明白为什么我会遇到这个问题。博客和帖子中提供的答案已经在我的代码中实现,我仍然面临这个问题(或者我仍然无法弄清楚我的代码编译失败的原因)

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

但仍然是同样的错误。任何线索我在这里做错了什么。

4

1 回答 1

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
   }
}
于 2015-04-23T21:20:56.613 回答