Issue
I would like to create an object for the Faculty class(child class of FacultyApp), where I can input some values
error: incompatible types: String cannot be converted to TextField Faculty faculty = new Faculty(" ", " ", " ");
FXMLDocumentController
public class FXMLDocumentController implements Initializable {
private Label label;
@FXML
private TextField employeeName;
@FXML
private TextField employeeTitle;
@FXML
private TextField emailAddress;
@FXML
private Button SaveButton;
@Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
public void setNAME(TextField employeeName) {
employeeName.getText();
}
public void setADDRESS(TextField emailAddress) {
emailAddress.getText();
}
public void setTITLE(TextField employeeTitle) {
employeeTitle.getText();
}
@FXML
private void saveInfo(ActionEvent event) {
Faculty faculty = new Faculty(" ", " ", " ");
String textField = new TextField().toString();
faculty.setNAME(employeeName);
faculty.setADDRESS(emailAddress);
faculty.setTITLE(employeeTitle);
String message = "YOUR INPUT HAS BEEN SAVED";
Alert a = new Alert(AlertType.INFORMATION);
a.setContentText(message +"\nEmployee Name: "+employeeName +"\nEmployee Title: "+ employeeTitle +"\nEmail Address: " + emailAddress);
a.show();
}
}
childClass from MainClass
public class Faculty extends FacultyApp{ private TextField title, name, address;
public Faculty (TextField employeeName, TextField emailAddress, TextField employeeTitle){
title = employeeTitle;
name = employeeName;
address = emailAddress;
}
public void setNAME(TextField employeeName) {
name = employeeName;
}
public TextField getNAME(){
return name;
}
public void setADDRESS(TextField emailAddress) {
address = emailAddress;
}
public TextField getADDRESS(){
return address;
}
public void setTITLE(TextField employeeTitle) {
title = employeeTitle;
}
public TextField getTITLE(){
return title;
}
}
Solution
Your Faculty
Class' constructor expects 3 arguments of type TextField
, but you're trying to pass 3 String
Objects.
Since you're using setters, why don't you remove the current constructor and create a new Faculty
Object by using the default constructor?
So remove this from the Faculty
class:
public Faculty (TextField employeeName, TextField emailAddress, TextField employeeTitle){
title = employeeTitle;
name = employeeName;
address = emailAddress;
}
And in FXMLDocumentController
change
Faculty faculty = new Faculty(" ", " ", " ");
into
Faculty faculty = new Faculty();
Answered By - TimonNetherlands