我目前的项目结构如下
MainStage的
| _主控制器
| _ MainScene.fxml
public class MainController implements Initializable {
@FXML
public void switchToEmail() throws Exception{
EmailController ec = new EmailController();
ec.display();
}
我使用fx:controller在MainScene.fxml中加载了MainController
我有另一个舞台
EmailStage
| _Email控制器
| _Email场景
public class EmailController implements Initializable{
HashMap emails;
@FXML
public static TextArea emailSceneTextArea;
@FXML
public void display(){
emails = new HashMap<Integer, String>();
String responseEmails = null;
System.out.println(emailSceneTextArea.getText());
try {
responseEmails = this.getEmails().trim();
} catch (Exception ex) {
System.out.println("responseEmail Exception in EmailController.java");
}
emails = ParseXml.parse(responseEmails, "emails");
Set s = emails.keySet();
Iterator it = s.iterator();
while (it.hasNext()) {
Integer i = (Integer)it.next();
String text = emailSceneTextArea.getText(); /*NullPointerException Line*/
String email = (String) emails.get(i);
emailSceneTextArea.setText(text+email);
}
}
public String getEmails() throws Exception{
RequestHandler rq = new RequestHandler();
return rq.prepare("fetchEmails", "nothing");
}
我使用fx:controller
在emailScene.fxml中加载了EmailController
当我将舞台切换到emailStage时
在EmailController中,我得到了NullPointerException&#39;在线提到。我哪里做错了?
P.S =在我通过emailScene.fxml的按钮操作调用display方法后浪费了几个小时。有效。困惑为什么?
答案 0 :(得分:0)
如果我错了,请纠正我,但......在emailSceneTextArea中存储了哪些数据。
看起来你正试图获得不存在的文字。