Java错误:构造函数未定义

Java中,为什么我会收到此错误:

Error: The constructor WeightIn() is undefined

Java代码:

public class WeightIn{
  private double weight;
  private double height;

  public WeightIn (double weightIn, double heightIn){
    weight = weightIn;
    height = heightIn;
  }
  public void setWeight(double weightIn){
    weight = weightIn;
  }
  public void setHeight(double heightIn){
    height = heightIn;
  }
}

public class WeightInApp{
  public static void main (String [] args){
    WeightIn weight1 = new WeightIn();         //Error happens here.
    weight1.setWeight(3.65);
    weight2.setHeight(1.7);
  }
}

我有一个构造函数定义.

最佳答案
将此添加到您的班级:

public WeightIn(){
}

>请理解,只有在没有编写其他构造函数时才提供默认的无参数构造函数
>如果编写任何构造函数,则编译器不提供默认的no-arg构造函数.你必须指定一个.

转载注明原文:Java错误:构造函数未定义 - 代码日志