我正在尝试在EditPage类中有一个MainPage实例,同时在MainPage类中有一个EditPage实例。 但是,我得到例外。为什么会发生此异常?以及如何解决这个问题?
这是我的应用程序类,它有一个main方法:
package application;
import javafx.application.Application;
import javafx.stage.Stage;
import pages.MainPage;
public class Main extends Application {
@Override
public void start(Stage stage) {
try {
data.fileSetUp();
data.loadMeta();
mainScene.setAlwaysOnTop(stage);
mainScene.updateAlwaysOnTop(stage);
mainScene.setEditAction(stage);
stage.setScene(mainScene.getScene());
stage.show();
stage.setOnCloseRequest(e->{
try {
data.saveMeta();
} catch (Exception e1) {
e1.printStackTrace();
}
});
} catch(Exception e) {
e.printStackTrace();
}
}
DataControl data = new DataControl();
MainPage mainScene = new MainPage();
public static void main(String[] args) {
launch(args);
}
}
这是一个MainPage类:
package pages;
import java.util.ArrayList;
import application.DataControl;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class MainPage {
public Scene getScene(){
arrayReady.add(txtReady1);arrayReady.add(txtReady2);arrayReady.add(txtReady3);arrayReady.add(txtReady4);arrayReady.add(txtReady5);
for (Text txt:arrayReady){
txt.setStyle("-fx-font-size: 20");
}
arrayEdit.add(lEdit1);arrayEdit.add(lEdit2);arrayEdit.add(lEdit3);arrayEdit.add(lEdit4);arrayEdit.add(lEdit5);
for (Label label:arrayEdit){
label.setStyle("-fx-font-size: 20");
}
arrayMenu.add(lAlwaysOnTop);arrayMenu.add(lControl);
for (Label label:arrayMenu){
label.setStyle("-fx-font-size: 15");
}
gridReadyEdit.addColumn(0, txtReady1,txtReady2,txtReady3,txtReady4,txtReady5);
gridReadyEdit.addColumn(1, lEdit1,lEdit2,lEdit3,lEdit4,lEdit5);
gridReadyEdit.setAlignment(Pos.CENTER);
gridReadyEdit.setHgap(20);
gridReadyEdit.setMaxSize(300, 0);
gridMenu.addRow(0, lAlwaysOnTop,lControl);
gridMenu.setAlignment(Pos.CENTER);
gridMenu.setHgap(20);
gridMenu.setMaxSize(300, 0);
gridMenu.setStyle("-fx-border-color:lightgrey");
pane.getChildren().addAll(gridReadyEdit,gridMenu,lVersion);
StackPane.setAlignment(gridMenu, Pos.TOP_CENTER);
StackPane.setAlignment(lVersion, Pos.BOTTOM_CENTER);
return scene;
}
public void setEditAction(Stage stage){
arrayEdit.clear();
arrayEdit.add(lEdit1);arrayEdit.add(lEdit2);arrayEdit.add(lEdit3);arrayEdit.add(lEdit4);arrayEdit.add(lEdit5);
for (Label label:arrayEdit){
label.setOnMousePressed(e->{
stage.setScene(editPage.getScene());
});
}
}
public void setAlwaysOnTop(Stage stage){
lAlwaysOnTop.setOnMousePressed(e->{
if (DataControl.checkAlwaysOnTop == 1){
DataControl.checkAlwaysOnTop = 0;
updateAlwaysOnTop(stage);
} else {
DataControl.checkAlwaysOnTop = 1;
updateAlwaysOnTop(stage);
}
});
}
public void updateAlwaysOnTop(Stage stage){
if (DataControl.checkAlwaysOnTop == 1){
lAlwaysOnTop.setText("Always On Top: Yes");
stage.setAlwaysOnTop(true);
} else {
lAlwaysOnTop.setText("Always On Top: No");
stage.setAlwaysOnTop(false);
}
}
public GridPane getGridMenu(){return gridMenu;}
private ArrayList<Text> arrayReady = new ArrayList<Text>();
private ArrayList<Label> arrayEdit = new ArrayList<Label>();
private ArrayList<Label> arrayMenu = new ArrayList<Label>();
private Label lVersion = new Label("Version 1.0");
private Label lEdit1 = new Label("EDIT");
private Label lEdit2 = new Label("EDIT");
private Label lEdit3 = new Label("EDIT");
private Label lEdit4 = new Label("EDIT");
private Label lEdit5 = new Label("EDIT");
private Label lAlwaysOnTop = new Label();
private Label lControl = new Label("Control Setting");
private Text txtReady1 = new Text("1. Ready");
private Text txtReady2 = new Text("2. Ready");
private Text txtReady3 = new Text("3. Ready");
private Text txtReady4 = new Text("4. Ready");
private Text txtReady5 = new Text("5. Ready");
private GridPane gridMenu = new GridPane();
private GridPane gridReadyEdit = new GridPane();
private StackPane pane = new StackPane();
private Scene scene = new Scene(pane,300,300);
private EditPage editPage = new EditPage();
}
这是一个EditPage类:
package pages;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
public class EditPage{
public Scene getScene(){
pane.getChildren().addAll();
return scene;
}
private StackPane pane = new StackPane();
private Scene scene = new Scene(pane,300,300);
private MainPage mainPage = new MainPage();
}
最后,这是一条错误消息:
Exception in Application constructor
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Unable to construct Application instance: class application.Main
at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$152(Unknown Source)
at com.sun.javafx.application.LauncherImpl$$Lambda$50/1645995473.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$158(Unknown Source)
at com.sun.javafx.application.LauncherImpl$$Lambda$51/2125582483.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$172(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$45/186276003.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$170(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$48/1698672883.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(Unknown Source)
at com.sun.javafx.application.PlatformImpl$$Lambda$47/237061348.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$145(Unknown Source)
at com.sun.glass.ui.win.WinApplication$$Lambda$36/2117255219.run(Unknown Source)
... 1 more
Caused by: java.lang.StackOverflowError
at java.util.TimSort.countRunAndMakeAscending(Unknown Source)
at java.util.TimSort.sort(Unknown Source)
at java.util.Arrays.sort(Unknown Source)
at java.util.ArrayList.sort(Unknown Source)
at java.util.Collections.sort(Unknown Source)
at com.sun.javafx.css.SelectorPartitioning.match(Unknown Source)
at com.sun.javafx.css.StyleManager.findMatchingStyles(Unknown Source)
at javafx.scene.CssStyleHelper.createStyleHelper(Unknown Source)
at javafx.scene.Node.reapplyCss(Unknown Source)
at javafx.scene.Node.impl_reapplyCSS(Unknown Source)
at javafx.scene.Node.invalidatedScenes(Unknown Source)
at javafx.scene.Node.setScenes(Unknown Source)
at javafx.scene.Scene$9.invalidated(Unknown Source)
at javafx.beans.property.ObjectPropertyBase.markInvalid(Unknown Source)
at javafx.beans.property.ObjectPropertyBase.set(Unknown Source)
at javafx.scene.Scene.setRoot(Unknown Source)
at javafx.scene.Scene.<init>(Unknown Source)
at javafx.scene.Scene.<init>(Unknown Source)
at pages.MainPage.<init>(MainPage.java:115)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
Exception running application application.Main
答案 0 :(得分:0)
为什么会发生此异常?
java.lang.reflect.InvocationTargetException
发生了,因为在JavaFX应用程序启动时出现了错误(抛出了异常)。
您可以通过检查堆栈跟踪找出问题所在。特别是,查看嵌套异常。在这种情况下,最终的“原因”例外是StackOverflowError
。
那导致StackOverflowError
的原因是什么?从堆栈帧判断,有一个“无限递归”,其中:
MainPage
创建EditPage
EditPage
创建MainPage
MainPage
创建EditPage
EditPage
创建MainPage
这方面的证据是堆栈帧的重复模式:
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
at pages.EditPage.<init>(EditPage.java:23)
at pages.MainPage.<init>(MainPage.java:117)
粗略检查一下代码会告诉你它在哪里发生。 (提示:<init>
表示它在对象构造期间发生,堆栈跟踪甚至会告诉您源代码行号!)
以及如何解决这个问题?
修复代码中导致无限递归的错误。
几乎可以肯定...... EditPage
不应该创建MainPage
。您可能需要将MainPage
的引用作为EditPage
构造函数的参数传递。