我正在使用 java 和 javafx (Scenebuilder) 进行此分配,我试图将一些字符串传递给我在其自己的类中定义的构造函数,但即使我正确地遵循所有格式,它也会不断给我错误。请查看图片以供参考。现在为此工作了几个小时 :')
错误:构造函数联系人(字符串,字符串,字符串,字符串)未定义
我的联系人构造文件名为 contact.java(控制器定义的第 9 和 12 行)
public class contact {
private String FirstName;
private String LastName;
private String email;
private String phonenum;
//private String largeImage;
public contact() {
this("", "", "", "");
}
public contact(String firstName, String lastName, String email, String phoneNumber) {
this.FirstName = firstName;
this.LastName = lastName;
this.email = email;
this.phonenum = phoneNumber;}
public String getFirstName() {return FirstName;}
public void setFirstName(String FirstName) {this.FirstName = FirstName;}
public String getLastName() {return LastName;}
public void setLastName(String LastName) {this.LastName = LastName;}
public String getemail() {return email;}
public void setemail(String email) {this.email = email;}
public String getphonenum() {return phonenum;}
public void setphonenum(String phonenum) {this.phonenum = phonenum;}
//public String getLargeImage() {return largeImage;}
//public void setLargeImage(String largeImage) {this.largeImage = largeImage;}
@Override
public String toString() {return getLastName();}
}
这是我尝试初始化它的地方 contactviewController.java(第 73 行)
public void initialize() {
contactcheck.add(new contact("elliot","Mathew","le@","1234"));
contactListView.setItems(contactcheck);//bind contactlistview to contact check
contactListView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<contact>() {
@Override
public void changed(ObservableValue<? extends contact> arg0, contact oldValue, contact newValue) {
selectedcontact = newValue;
firstNameTextField.setText(newValue.getFirstName());
lastNameTextField.setText(newValue.getLastName());
emailTextField.setText(newValue.getemail());
phoneNumberTextField.setText(newValue.getphonenum());
}
});
}
}
这里是定义可观察列表和联系检查的地方(第 17 行)