The Typholorian Posted August 15, 2023 Share Posted August 15, 2023 Caused by: java.lang.NullPointerException: Cannot read field "level" because "this.minecraft" is null This is my first big error when coding. I looked it up, but there are a bunch of references to Dawncraft and not enough to figure out what was going wrong. I found this, but it involves a command and my GUI only opens when you shift + right-click while holding an item. They fixed it by not calling it with a command, but I am not using a command. Here's the render of my menu, which is the only part that changed between it working and not: @Override public void render(@Nonnull PoseStack mstack, int mouseX, int mouseY, float partialTicks) { int midx = this.width / 2; int midy = this.height / 2; this.renderBackground(mstack); drawCenteredString(mstack, font, I18n.get("config.shape_tool"), midx, 4, 0xC3D1D8); Utils.renderImage(midx - 12, midy, 20, 20, "textures/gui/plus.png", mstack); addRenderableWidget(new Button(midx - 12, midy, 10, 10, Component.translatable(""), this::increaseax)); Utils.renderImage(midx + 12, midy, 20, 20, "textures/gui/minus.png", mstack); addRenderableWidget(new Button(midx + 12, midy, 10, 10, Component.translatable(""), this::decreaseax)); drawCenteredString(mstack, font, String.valueOf(shapetoolax), midx, midy + 10, 0xC3D1D8); super.render(mstack, mouseX, mouseY, partialTicks); } Utils.renderImage is this: public static void renderImage(int x, int y, int width, int height, String img, PoseStack mstack) { RenderSystem.setShaderColor(1, 1, 1, 1); RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); RenderSystem.setShaderTexture(0, new ResourceLocation(PNegative.MODID, img)); blit(mstack, x, y, 0, 0, width, height, width, height); RenderSystem.disableBlend(); } I have used it before and it has worked, so it can't be a problem. Quote Link to comment Share on other sites More sharing options...
The Typholorian Posted August 15, 2023 Author Share Posted August 15, 2023 Update: I restarted the game and it was working, but when I closed the menu and re-opened it it crashed with error message Caused by: java.net.UnknownHostException: sessionserver.mojang.com. Quote Link to comment Share on other sites More sharing options...
warjort Posted August 15, 2023 Share Posted August 15, 2023 Your question is pretty much unanswerable. You don't show all the relevant code and don't even post the full error message. Don't post code incomplete snippets in the forum. Put a minimal project on github that reproduces your problem that we can look at and run for ourselves. Or just your full project with instructutions on how to reproduce the issue and a pointer to relevant code. Guess (I shouldn't have to guess): Quote Caused by: java.lang.NullPointerException: Cannot read field "level" because "this.minecraft" is null This error looks like you caching something in a static field that has now become invalid. Or otherwise reusing an object that is no longer valid. Don't put stuff in static fields unless it is effectively immutable. Doing so will at best give you weird bugs. At worst it will cause memory leaks and data corruption. Quote Boilerplate: If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one. If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install Large files should be posted to a file sharing site like https://gist.github.com You should also read the support forum sticky post. Link to comment Share on other sites More sharing options...
Recommended Posts
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.