0

So, I'm getting a StackOverflowError (Unwrapped from a InvocationTargetException), and I can't for the life of me figure out why.

package gui;
import errorhandling.ErrorLogBook;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class GUIRouter extends Application{

public static void main(String[] args)
{
    try
    {
        Application.launch(GUIRouter.class, (String[])null);
    }
    catch (Exception e)
    {
        System.out.println(e.getCause().toString());
    }
}

@Override
public void start (Stage primaryStage)
{
    try
    {
        StackPane page = (StackPane) FXMLLoader.load(GUIRouter.class.getResource("LoginScreen.fxml"));
        Scene scene = new Scene(page);
        primaryStage.setScene(scene);
        primaryStage.show();
    }
    catch (Exception e)
    {
        ErrorLogBook.logReport(e);
    }
}

It fails at the first try block with:

Application.launch(GUIRouter.class, (String[])null);

This is a FXML application that I'm building with NetBeans and JavaFX Scene Builder 2.0

Any ideas about why my code keeps crashing?

mhasan
  • 3,703
  • 1
  • 18
  • 37
Austen Clay
  • 39
  • 1
  • 8
  • 3
    A StackOverflow generally has a section that just repeats over and over, if that is the case it'd be helpful if you provided it. – Kiskae Oct 04 '16 at 17:47
  • 1
    add `e.printStackTrace()` to the catch clauses so that you see the full (or as full as it can be for a stack overflow) stack traces on the console... – mihi Oct 04 '16 at 17:49
  • Also show your `ErrorLogBook` class, perhaps that contains the stack overflow? – mihi Oct 04 '16 at 17:50
  • 1. As previously requested, post the repeating part of the stack trace. 2. Remove the `ErrorLogBook` call and replace it with a regular `e.printStackTrace()` to ensure the `ErrorLogBook` is not part of the problem. 3. It's probably inadvisable to pass `null` as the parameter list; pass an empty array instead (which you can do simply with `Application.launch(GUIRouter.class);`). 4. Post the controller class for the FXML file. – James_D Oct 04 '16 at 18:46

4 Answers4

1

My guess would be that your .fxml in "LoginScreen.fxml" has GuiRouter defined as its controller, which it then creates through reflection. My guess is that during that creation it ends up calling start(..) creating a loop.

Kiskae
  • 24,655
  • 2
  • 77
  • 74
  • And if this is the case, see http://stackoverflow.com/questions/32081713/javafx-controller-class-not-working and http://stackoverflow.com/questions/33303167/javafx-can-application-class-be-the-controller-class – James_D Oct 04 '16 at 19:33
  • @Kiskae nice guess! – Amin Oct 04 '16 at 19:53
0

Without having the .fxml file and/or the stack trace, I (see no way but to ) guess the main cause of the exception in exactly the same way as Kiskae did. However, why you do not replace the line

Application.launch(GUIRouter.class, (String[])null);

with the more simpler form

Application.launch(args);

Or at least

Application.launch(args, new String[0]);

To see if the exception still remains.

James_D
  • 201,275
  • 16
  • 291
  • 322
Amin
  • 292
  • 2
  • 11
0

Try this:

package gui;
import errorhandling.ErrorLogBook;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class GUIRouter extends Application{

    public static void main(String[] args)
    {
        launch(args);
    }

    @Override
    public void start (Stage primaryStage)
    {
        try
        {
            StackPane page = FXMLLoader.load(getClass().getResource("/gui/LoginScreen.fxml"));
            Scene scene = new Scene(page);
            primaryStage.setScene(scene);
            primaryStage.show();
        }
        catch (Exception e)
        {
            e.printStackTrace();
            ErrorLogBook.logReport(e);
        }


}
Nevets17
  • 109
  • 1
  • 9
-1

Thanks for all the responses! However, after playing around with it, I have found the root of the problem. I replaced

StackPane page = (StackPane) FXMLLoader.load(GUIRouter.class.getResource("LoginScreen.fxml"));

with

Parent root = FXMLLoader.load(getClass().getResource("LoginScreen.fxml"));

and now it's working just fine.

Austen Clay
  • 39
  • 1
  • 8