我是一个初学者,并试图编译我的工作。但是它不起作用。我收到这个错误
"constructor account in class account cannot be applied to given types;
required: in,java,lang,String; found: no arguments; reason: actual and formal argument lists differ in..."
如果有人能向我解释这一点,将非常感激。
这很可能意味着您忘记将参数传递给构造函数。
class Account {
Account(String name) {
// ....
}
}
// somewhere in the code:
Account account = new Account(); // invalid, no arguments found, java.lang.String needed
Account account = new Account("some name"); // ok
请注意,在 Java 中,当您添加带参数的构造函数时,不会自动生成默认的无参数构造函数,您必须自己提供一个:
class Account {
Account() {
// ....
}
Account(String name) {
// ....
}
}
Account account = new Account(); // ok
Account account = new Account("some name"); // ok