Can't call functions from built screen

Hi, I’m trying to pass parameters to a screen I’ve built using the ScreenBuilders bean by calling a function and passing parameters to the function. It’s the same method that’s used here and it worked fine for me before, but after refactoring some code it doesn’t work anymore. Does anybody know why? Here’s what my code looks like right now:

@Inject
private ScreenBuilders screenBuilders;

private void goToForm() {
    FormScreen form = screenBuilders.screen(this)
        .withScreenClass(FormScreen.class)
        .build();
    form.setParams("foo");
    log.debug("Made it this far!");
    form.show();
}

“foo” doesn’t get passed to FormScreen and “Made it this far!” doesn’t show up in the log, so I’m assuming this code stops being executed after .build(); is called, but then why did this work before and why does the wiki claim this should work?

If “code stops being executed…” there would be an Exception. Is there? If not, are you sure the goToForm method is even being executed? Try putting a log call before the screenBuilders call and see if for some reason goToForm isn’t being executed.

1 Like

If “code stops being executed…” there would be an Exception.

I realized that the screen I was trying to show was throwing an exception on init because setParams hadn’t been called yet. I changed that part to run after setParams and everything works as intended now. Thanks!

1 Like