I'm coding an Email-client with j=JavaFX. Now I'm trying to write down the reply button and I get the java.lang.reflect.InvocationTargetException
, when I try to find the Sender of the Email to reply. Here's the Replaycontroller code:
package project;
import java.io.IOException;
import java.net.URL;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;
import javafx.fxml.FXML;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import static project.FXMLNewMailController.mittenti;
public class FXMLReplayController implements Initializable {
@FXML
private Button Btn_send;
@FXML
private TextField Txt_object;
@FXML
private TextField Txt_receiver;
@FXML
private TextArea Area_text;
@FXML
private AnchorPane AP_replace;
private static String author, send;
private static Mail mail;
static String mittenti[] = {"marti.anzo@gmail.it", "andrea.pizza@hotmail.com", "mattia.berni@edu.unito.it"};
public void setAuthor(String author) {
this.author = author;
}
public String getAuthor() {
return author;
}
@Override
public void initialize(URL url, ResourceBundle rb) {
//Txt_receiver.setText(getMessaggio().getSender(); //error
}
public void setMessaggio(Mail mail){
this.mail = mail;
}
public Mail getMessaggio(){
return mail;
}
}
The Txt_receiver.setText(getMessaggio().getSender();
leave me the error, if I comment this section it works, but I need to get the Sender to Replay the email successfully. The getMessage()
method is in this class, the getSender()
one is declared in the Mail class.
The button handler code:
private void handleBtnReplay(ActionEvent event) throws IOException{
System.out.println("Inoltra");
try{
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("FXMLReplay.fxml"));
Parent rootRW = (AnchorPane) fxmlLoader.load();
Stage stage = new Stage();
stage.setTitle("Replay");
FXMLReplayController control = fxmlLoader.<FXMLReplayController>getController();
control.setMessaggio(getMail());
System.out.println("rispondo a: " + control.getMessaggio());
System.out.println("destinatario: " + getMail().getSender());
stage.setScene(new Scene(rootRW));
stage.show();
}catch (Exception e) {
System.out.println("errore inoltra: "+ e);
}
}
I never found this error before and searching online I can't understand what's the point with this 2 get methods.