Jump to content

Minecraft crashes with NullPointerException when calling a custom GUI the second time.


Recommended Posts

Posted (edited)

I'm lost on this one. It's my first time working with the Screen class and I just can't get it to work. I simply want to add a few buttons to minecraft's advancement screen when the user typed a certain command. So I thought the easiest way is to simply extend the AdvancementsScreen class and render my buttons on top through my GUI. It works fine on the first time executing the command, but when I close out of the Screen and type in the command again opening the Screen, the game crashes with a NullPointerException in class Screen caused by "this.minecraft" is null:

---- Minecraft Crash Report ----
// This is a token for 1 free hug. Redeem at your nearest Mojangsta: [~~HUG~~]

Time: 2023-01-16 19:57:41
Description: Rendering screen

java.lang.NullPointerException: Cannot read field "level" because "this.minecraft" is null
	at net.minecraft.client.gui.screens.Screen.renderBackground(Screen.java:442) ~[forge-1.19.2-43.2.0_mapped_parchment_2022.11.27-1.19.2-recomp.jar%23181!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.screens.Screen.renderBackground(Screen.java:438) ~[forge-1.19.2-43.2.0_mapped_parchment_2022.11.27-1.19.2-recomp.jar%23181!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.screens.advancements.AdvancementsScreen.render(AdvancementsScreen.java:108) ~[forge-1.19.2-43.2.0_mapped_parchment_2022.11.27-1.19.2-recomp.jar%23181!/:?] {re:mixin,pl:runtimedistcleaner:A,re:classloading,pl:mixin:APP:customadvancements.mixins.json:MixinAdvancementsScreen,pl:mixin:A,pl:runtimedistcleaner:A}
	at de.thedead2.customadvancements.generator.gui.AdvancementGeneratorGUI.render(AdvancementGeneratorGUI.java:41) ~[%23186!/:?] {re:classloading}
	at net.minecraftforge.client.ForgeHooksClient.drawScreenInternal(ForgeHooksClient.java:440) ~[forge-1.19.2-43.2.0_mapped_parchment_2022.11.27-1.19.2-recomp.jar%23180%23187!/:?] {re:classloading}
	at net.minecraftforge.client.ForgeHooksClient.drawScreen(ForgeHooksClient.java:433) ~[forge-1.19.2-43.2.0_mapped_parchment_2022.11.27-1.19.2-recomp.jar%23180%23187!/:?] {re:classloading}
	at net.minecraft.client.renderer.GameRenderer.render(GameRenderer.java:908) ~[forge-1.19.2-43.2.0_mapped_parchment_2022.11.27-1.19.2-recomp.jar%23181!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.runTick(Minecraft.java:1141) ~[forge-1.19.2-43.2.0_mapped_parchment_2022.11.27-1.19.2-recomp.jar%23181!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.run(Minecraft.java:705) ~[forge-1.19.2-43.2.0_mapped_parchment_2022.11.27-1.19.2-recomp.jar%23181!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.main.Main.run(Main.java:212) ~[forge-1.19.2-43.2.0_mapped_parchment_2022.11.27-1.19.2-recomp.jar%23181!/:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.main.Main.main(Main.java:51) ~[forge-1.19.2-43.2.0_mapped_parchment_2022.11.27-1.19.2-recomp.jar%23181!/:?] {re:classloading,pl:runtimedistcleaner:A}
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?] {}
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}
	at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?] {}
	at net.minecraftforge.fml.loading.targets.ForgeClientUserdevLaunchHandler.lambda$launchService$0(ForgeClientUserdevLaunchHandler.java:25) ~[fmlloader-1.19.2-43.2.0.jar%2394!/:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:30) [modlauncher-10.0.8.jar%23107!/:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) [modlauncher-10.0.8.jar%23107!/:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) [modlauncher-10.0.8.jar%23107!/:?] {}
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) [modlauncher-10.0.8.jar%23107!/:?] {}
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) [modlauncher-10.0.8.jar%23107!/:?] {}
	at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) [modlauncher-10.0.8.jar%23107!/:?] {}
	at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) [modlauncher-10.0.8.jar%23107!/:?] {}
	at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141) [bootstraplauncher-1.1.2.jar:?] {}


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Render thread
Stacktrace:
	at net.minecraft.client.gui.screens.Screen.renderBackground(Screen.java:442) ~[forge-1.19.2-43.2.0_mapped_parchment_2022.11.27-1.19.2-recomp.jar%23181!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.screens.Screen.renderBackground(Screen.java:438) ~[forge-1.19.2-43.2.0_mapped_parchment_2022.11.27-1.19.2-recomp.jar%23181!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.screens.advancements.AdvancementsScreen.render(AdvancementsScreen.java:108) ~[forge-1.19.2-43.2.0_mapped_parchment_2022.11.27-1.19.2-recomp.jar%23181!/:?] {re:mixin,pl:runtimedistcleaner:A,re:classloading,pl:mixin:APP:customadvancements.mixins.json:MixinAdvancementsScreen,pl:mixin:A,pl:runtimedistcleaner:A}
	at de.thedead2.customadvancements.generator.gui.AdvancementGeneratorGUI.render(AdvancementGeneratorGUI.java:41) ~[%23186!/:?] {re:classloading}
	at net.minecraftforge.client.ForgeHooksClient.drawScreenInternal(ForgeHooksClient.java:440) ~[forge-1.19.2-43.2.0_mapped_parchment_2022.11.27-1.19.2-recomp.jar%23180%23187!/:?] {re:classloading}
	at net.minecraftforge.client.ForgeHooksClient.drawScreen(ForgeHooksClient.java:433) ~[forge-1.19.2-43.2.0_mapped_parchment_2022.11.27-1.19.2-recomp.jar%23180%23187!/:?] {re:classloading}
-- Screen render details --
Details:
	Screen name: de.thedead2.customadvancements.generator.gui.AdvancementGeneratorGUI
	Mouse location: Scaled: (213, 120). Absolute: (427.000000, 240.000000)
	Screen size: Scaled: (427, 240). Absolute: (1708, 960). Scale factor of 4.000000
Stacktrace:
	at net.minecraft.client.renderer.GameRenderer.render(GameRenderer.java:908) ~[forge-1.19.2-43.2.0_mapped_parchment_2022.11.27-1.19.2-recomp.jar%23181!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.runTick(Minecraft.java:1141) ~[forge-1.19.2-43.2.0_mapped_parchment_2022.11.27-1.19.2-recomp.jar%23181!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.run(Minecraft.java:705) ~[forge-1.19.2-43.2.0_mapped_parchment_2022.11.27-1.19.2-recomp.jar%23181!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.main.Main.run(Main.java:212) ~[forge-1.19.2-43.2.0_mapped_parchment_2022.11.27-1.19.2-recomp.jar%23181!/:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.main.Main.main(Main.java:51) ~[forge-1.19.2-43.2.0_mapped_parchment_2022.11.27-1.19.2-recomp.jar%23181!/:?] {re:classloading,pl:runtimedistcleaner:A}
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?] {}
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}
	at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?] {}
	at net.minecraftforge.fml.loading.targets.ForgeClientUserdevLaunchHandler.lambda$launchService$0(ForgeClientUserdevLaunchHandler.java:25) ~[fmlloader-1.19.2-43.2.0.jar%2394!/:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:30) [modlauncher-10.0.8.jar%23107!/:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) [modlauncher-10.0.8.jar%23107!/:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) [modlauncher-10.0.8.jar%23107!/:?] {}
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) [modlauncher-10.0.8.jar%23107!/:?] {}
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) [modlauncher-10.0.8.jar%23107!/:?] {}
	at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) [modlauncher-10.0.8.jar%23107!/:?] {}
	at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) [modlauncher-10.0.8.jar%23107!/:?] {}
	at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141) [bootstraplauncher-1.1.2.jar:?] {}
    
    

From my understanding the init() method of the Screen class sets the minecraft instance used by the class, so it shouldn't be null?!

That's the class extending the AdvancementsScreen class, no own methods, only calling the super class:

https://gist.github.com/thedead2/6c9dbe36b6d87e3aa838974897fb6d2d

 

Also tried to create a simple Screen extending the Screen class:

https://gist.github.com/thedead2/69d2422725bfe69f1274f6034153d2e1

 

but it crashes with a similar error also stating that "this.minecraft" is null.

 

Am I missing something?

Edited by The_Dead_2
Spelling mistake
Posted

Just in case some one has the same problem:

After a lot of testing I figured out that this problem seems to be related with minecrafts commands and how they are executed. Apparently if you try to open any screen through the use of a command, this causes a lot of weird bugs, like not rendering the screen every time the command is executed or that the game crashes with a NullPointerException.

For me, I fixed it by using a certain key to open the custom screen instead of trying to open the screen via a command.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.