错误';主板(java.lang.String、java.lang.String、float、java.lang.String)';在';主板';无法应用于';()';

错误';主板(java.lang.String、java.lang.String、float、java.lang.String)';在';主板';无法应用于';()';,java,class,Java,Class,我一直试图在另一个类中实例化一个类的对象,但它给出了标题中描述的错误 例如,下面是代码的样子: package com.company; public class Desktop { private String coolerType; public MotherBoard mb = new MotherBoard(); public GraphicsCard gpu = new GraphicsCard(); public String getCoole

我一直试图在另一个类中实例化一个类的对象,但它给出了标题中描述的错误

例如,下面是代码的样子:

package com.company;

public class Desktop {
    private String coolerType;

    public MotherBoard mb = new MotherBoard();

    public GraphicsCard gpu = new GraphicsCard();

    public String getCoolerType() {
        return coolerType;
    }

    public void setCoolerType(String coolerType) {
        if(!this.coolerType.isEmpty()) {
            this.coolerType = coolerType;
        }
    }

    public Desktop(String coolerType) {
        this.coolerType = coolerType;
    }
}
“主板”和“GraphicsCard”是项目中的类,我想在“桌面”类中实例化它们


任何帮助都将不胜感激:)

主板构造函数接受4个参数。您正在尝试使用0调用它。您有两个选项:1。在主板上创建一个没有参数的构造函数,或者调用@Michael提到的需要4个参数的正确构造函数。