本文介绍了Application构造函数java.lang.reflect.InvocationTargetException中的JavaFX异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在EditPage类中有一个MainPage实例,同时在MainPage类中有一个EditPage实例。
然而,我得到例外。为什么会发生此异常?以及如何解决这个问题?

I am trying to have an instance of MainPage in EditPage class, while having an instance of EditPage in MainPage class.However, I get exception. Why this exception occur? and how to solve this problem?

这是我的应用程序类,它有一个main方法:

Here is my application class that has a main method:

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类:

Here is a MainPage class:

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类:

This is an EditPage class:

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();
}

最后,这是一条错误消息:

Lastly, Here is an error messages:

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


推荐答案

java.lang.reflect.InvocationTargetException 因为出错而发生( JavaFX应用程序启动时抛出了异常。

The java.lang.reflect.InvocationTargetException happened because something went wrong (and exception was thrown) while the JavaFX app was launching.

您可以通过检查堆栈跟踪找出问题所在。特别是,查看嵌套异常。在这种情况下,最终的因果异常是 StackOverflowError

You can find out what went wrong by examining the stack trace. In particular, look at the nested exceptions. In this case, the ultimate "cause" exception is a StackOverflowError.

那么是什么造成了的StackOverflowError ?从堆栈帧判断,有一个无限递归,其中:

So what caused the StackOverflowError? Well judging from stack frames, there is an "infinite recursion" where:


  • a MainPage 创建一个 EditPage

  • 一个 EditPage 创建一个 MainPage

  • a MainPage 创建 EditPage

  • 一个 EditPage 创建一个 MainPage

  • 依旧 ad infinitum

  • a MainPage creates an EditPage
  • an EditPage creates a MainPage
  • a MainPage creates an EditPage
  • an EditPage creates a MainPage
  • and so on ad infinitum.

这方面的证据是重复模式stackframes:

The evidence for this is the repeating pattern of stackframes:

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> 表示它在对象构造期间发生,并且堆栈跟踪甚至会告诉您源代码行号!)

A cursory examination of your code will show you where it is happening. (Hint: the <init> means that it is happening during object construction, and the stack trace even tells you the source code line numbers!)

修复错误你的代码导致无限递归。

Fix the bug in your code that is leading to the infinite recursion.

几乎可以肯定...... EditPage 不应该创建一个的MainPage 。您可能需要将对 MainPage 的引用作为参数传递给 EditPage 构造函数。

Almost certainly ... the EditPage should not be creating a MainPage. You probably need to pass a reference to the MainPage as an argument to the EditPage constructor.

这篇关于Application构造函数java.lang.reflect.InvocationTargetException中的JavaFX异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-18 09:50