UI.getCurrent() is null

Hello, I‘ve just updated my project from v14 to v23 and I get the error „Cannot invoke because return value of com.vaadin.flow.component.UI.getCurrent is null

Please show your code where this is null

It‘s in my MainLayout
„ThemeList themeList = UI.getCurrent().getElement().getThemeList();“

Where in the MainLayout do you use it?

i use it in the MainLayout method/function (i‘m not sure if it‘s called method or function)

You mean in the constructor

There it’s probably to early as the UI is not yet there

yeah sorry

weird… it worked on v14 and i set the „useDepreciatedV14Bootstrapping“ configuration on pom.xml to true (if that even changes anything

I’m not sure why it now doesn’t work

But I had issues in the past when doing something in the Layout constructor

Usedeprecatedv14bootstrap will be removed in Vaadin 24, so you should probably change the code instead. UI.getCurrent() shouldn’t be used, getUI() is better but it won’t solve your issue. You probably need to move your code to a different place like afternavigation if you can.

i‘ll try that, thank u

hmm very weird…
i get also get the same error when using UI.getCurrent().getLocale()

Yes because UI.getCurrent() is null

makes sense hahaha

had to create a properties file in „./src/main/resources“ and set „com.vaadin.experimental.webpackForFrontendBuild=true“

worked fine after that, thanks for the help

Caution! Webpack will be removed in the future. I would suggest you fix the issue

thanks for the warning👍🏼