我正在用j = JavaFX编码电子邮件客户端。现在,当我尝试找到要回复的电子邮件的发件人时,我尝试写下回复按钮,得到java.lang.reflect.InvocationTargetException
。这是Replaycontroller代码:
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;
}
}
Txt_receiver.setText(getMessaggio().getSender();
给我留下了错误,如果我对本节进行评论,它可以工作,但是我需要让发送方成功重播电子邮件。 getMessage()
方法在此类中,getSender()
方法在Mail类中声明。
按钮处理程序代码:
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);
}
}
我之前从未发现此错误,并且在线搜索无法理解这2种get方法的意义。