SwingWorker导致子类错误

时间:2012-04-03 05:28:34

标签: java netbeans swingworker

我有一个Class(称之为主类),主类中的方法调用其他类的方法。我已经在所有其他类中扩展了这个主类

      public class Evaluate extends Main

在我的主要班级我使用的是swingworker,所以我写了这样的代码

      class Main extends SwingWorker<Void, Void>{
        public Main(GUI frame) {
        p = frame;

        }
        //some more code 

现在当我构建这个程序时,它给了我以下错误

        error: constructor Main in class Main cannot be applied to given types;
        public class Evaluate extends Main {
        required: GUI
        found: no arguments
        reason: actual and formal argument lists differ in length

这里GUI包含我的应用程序启动的主要方法。请帮助我发生此错误的原因。

1 个答案:

答案 0 :(得分:2)

扩展类时,应该在自己的构造函数中调用主类的构造函数(使用super)。因此,在这种情况下,您的Evaluate类应该看起来像

public class Evaluate extends Main {

  public Evaluate( GUI frame ){
    super( frame );
  }
  // or another constructor
  public Evaluate( ){
    super( retrieveAFrameFromSomeWhere );
  }
  public Evaluate( loads of other arguments, GUI frame ){
    super( frame );
    //do something with the other arguments
  }
}

查看优秀的Java tutorial以获取更多信息,当然还有关于子类构造函数

的部分