NullPointerException when trying to build a screen using java code

I have one part of my UI that should be “dynamic” (plugin-based), and so there is one screen that I need to build in Java. I first build it in XML, to get it to work. After I finished converting it to Java, and removed it from the XML file, it crashed with a NullPointerException. I narrowed it down to this simplistic test case.

nifty.addScreen("create", new ScreenBuilder("create").build(nifty));

That gives me:

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
	at de.lessvoid.nifty.controls.dynamic.ScreenCreator.createScreen(
	at de.lessvoid.nifty.controls.dynamic.ScreenCreator.create(
	at com.blockwithme.client.ui.CreateController.setupScreen(

What am I doing wrong? It looks like the example I got from here:
Laying Out the GUI in Java

OK. I’m stupid. :frowning: “nifty” itself is null! I thought this could not be, as I thought it should have crashed directly in my code, but the fact is that java performs new ScreenBuilder(…) BEFORE calling that nifty.addScreen(…)