Terasology / TutorialNui

A series of tutorials for the NUI interface framework.
3 stars 10 forks source link

Tutorial does not build: NPE when opening screen #8

Closed IsaiahBlanks closed 4 years ago

IsaiahBlanks commented 4 years ago

See the page: TutorialNui Quick Start

When going through this quick introduction to NUI, it seems that the screen does not open at the first time the tutorial suggests you open it with showScreen environmentInfoScreen.

How To Reproduce

Follow the tutorial to set up the TutorialNui module, create the .ui file, and create the java class for your screen. Then, at the Step 2 header, when you try to open the screen, it won't open because of a NullPointerException.

Logs

ERROR o.t.logic.console.ConsoleImpl - An error occurred while executing a command
org.terasology.logic.console.commandSystem.exceptions.CommandExecutionException: java.lang.NullPointerException
    at org.terasology.logic.console.commandSystem.AbstractCommand.execute(AbstractCommand.java:242)
    at org.terasology.logic.console.ConsoleImpl.execute(ConsoleImpl.java:264)
    at org.terasology.logic.console.ConsoleImpl.execute(ConsoleImpl.java:228)
    at org.terasology.logic.console.ui.ConsoleScreen.lambda$initialise$0(ConsoleScreen.java:79)
    at org.terasology.rendering.nui.widgets.UIText.onKeyEvent(UIText.java:486)
    at org.terasology.logic.console.ui.UICommandEntry.onKeyEvent(UICommandEntry.java:83)
    at org.terasology.rendering.nui.internal.NUIManagerInternal.keyEvent(NUIManagerInternal.java:648)
    at org.terasology.rendering.nui.internal.NUIManagerInternalMethodAccess.invoke(Unknown Source)
    at org.terasology.entitySystem.event.internal.EventSystemImpl$ByteCodeEventHandlerInfo.invoke(EventSystemImpl.java:531)
    at org.terasology.entitySystem.event.internal.EventSystemImpl.sendConsumableEvent(EventSystemImpl.java:301)
    at org.terasology.entitySystem.event.internal.EventSystemImpl.send(EventSystemImpl.java:280)
    at org.terasology.entitySystem.entity.internal.BaseEntityRef.send(BaseEntityRef.java:205)
    at org.terasology.input.InputSystem.send(InputSystem.java:503)
    at org.terasology.input.InputSystem.sendKeyEvent(InputSystem.java:447)
    at org.terasology.input.InputSystem.processKeyboardInput(InputSystem.java:382)
    at org.terasology.input.InputSystem.update(InputSystem.java:135)
    at org.terasology.engine.modes.StateIngame.handleInput(StateIngame.java:192)
    at org.terasology.engine.subsystem.lwjgl.LwjglInput.postUpdate(LwjglInput.java:55)
    at org.terasology.engine.TerasologyEngine.tick(TerasologyEngine.java:473)
    at org.terasology.engine.TerasologyEngine.mainLoop(TerasologyEngine.java:427)
    at org.terasology.engine.TerasologyEngine.run(TerasologyEngine.java:403)
    at org.terasology.engine.Terasology.main(Terasology.java:163)
Caused by: java.lang.NullPointerException: null
    at org.terasology.rendering.nui.internal.NUIManagerInternal.createScreen(NUIManagerInternal.java:313)
    at org.terasology.rendering.nui.internal.NUIManagerInternal.createScreen(NUIManagerInternal.java:289)
    at org.terasology.rendering.nui.internal.NUIManagerInternal.pushScreen(NUIManagerInternal.java:340)
    at org.terasology.rendering.nui.internal.NUIManagerInternal.pushScreen(NUIManagerInternal.java:335)
    at org.terasology.rendering.nui.internal.NUIManagerInternal.pushScreen(NUIManagerInternal.java:78)
    at org.terasology.logic.console.commands.CoreCommands.showScreen(CoreCommands.java:321)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.terasology.logic.console.commandSystem.AbstractCommand.execute(AbstractCommand.java:237)
    ... 21 common frames omitted
IsaiahBlanks commented 4 years ago

It seems that the NPE is coming from the fact that the root and rootWidget fields come out null. These are set from the UIElement generated in NUIManagerInternal::createScreen when opening the screen for the tutorial.

jdrueckert commented 4 years ago

Copied @IsaiahBlanks's comment from Discord:

Turns out after a lot of looking through code and learning about reflection for a while (it seemed like even though I could see the module in game, it wasn't registering my class as a UIWidget), it turns out that https://github.com/Terasology/TutorialNui/issues/8 was simply fixed by reloading gradle and rebuilding the project :sweat_smile: . I suppose the issue should be closed now.

Hence, closing the issue.