Jump to content

Recommended Posts

Posted (edited)

Recently I have been trying to create a GUI. Right now I need to create a textfield which is what I am having trouble doing. I have created the TextFieldWidget and added it to render. However, whenever I click on it to add text to it the game crashes with this error:
 

---- Minecraft Crash Report ----
// Don't do that.

Time: 6/22/20 8:09 PM
Description: Rendering screen

java.lang.NullPointerException: Rendering screen
	at net.minecraft.client.gui.widget.TextFieldWidget.getNarrationMessage(TextFieldWidget.java:78) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.widget.Widget.narrate(Widget.java:89) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.widget.Widget.render(Widget.java:82) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at mypackage.GUIPunishKick.render(GUIPunishKick.java:82) ~[main/:?] {re:classloading}
	at net.minecraftforge.client.ForgeHooksClient.drawScreen(ForgeHooksClient.java:359) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading}
	at net.minecraft.client.renderer.GameRenderer.updateCameraAndRender(GameRenderer.java:492) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:957) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.run(Minecraft.java:554) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.main.Main.main(Main.java:177) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_212] {}
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_212] {}
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_212] {}
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_212] {}
	at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:55) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-5.0.0-milestone.4.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-5.0.0-milestone.4.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-5.0.0-milestone.4.jar:?] {}
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:81) [modlauncher-5.0.0-milestone.4.jar:?] {}
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:65) [modlauncher-5.0.0-milestone.4.jar:?] {}
	at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:102) [forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.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.widget.TextFieldWidget.getNarrationMessage(TextFieldWidget.java:78)
	at net.minecraft.client.gui.widget.Widget.narrate(Widget.java:89)
	at net.minecraft.client.gui.widget.Widget.render(Widget.java:82)
	at mypackage.GUIPunishKick.render(GUIPunishKick.java:82)
	at net.minecraftforge.client.ForgeHooksClient.drawScreen(ForgeHooksClient.java:359)

-- Screen render details --
Details:
	Screen name: mypackage.GUIPunishKick
	Mouse location: Scaled: (210, 104). Absolute: (421.000000, 209.000000)
	Screen size: Scaled: (427, 240). Absolute: (854, 480). Scale factor of 2.000000

-- Affected level --
Details:
	All players: 1 total; [ClientPlayerEntity['Dev'/125, l='MpServer', x=-111.72, y=98.02, z=46.35]]
	Chunk stats: Client Chunk Cache: 841, 499
	Level dimension: DimensionType{minecraft:overworld}
	Level name: MpServer
	Level seed: -3466772630709660509
	Level generator: ID 00 - default, ver 1. Features enabled: false
	Level generator options: {}
	Level spawn location: World: (-112,65,-240), Chunk: (at 0,4,0 in -7,-15; contains blocks -112,0,-240 to -97,255,-225), Region: (-1,-1; contains chunks -32,-32 to -1,-1, blocks -512,0,-512 to -1,255,-1)
	Level time: 107774 game time, 107774 day time
	Known server brands: 
	Level was modded: false
	Level storage version: 0x00000 - Unknown?
	Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)
	Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false
	Server brand: forge
	Server type: Integrated singleplayer server
Stacktrace:
	at net.minecraft.client.world.ClientWorld.fillCrashReport(ClientWorld.java:457)
	at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:1835)
	at net.minecraft.client.Minecraft.run(Minecraft.java:568)
	at net.minecraft.client.main.Main.main(Main.java:177)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:55)
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37)
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54)
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72)
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:81)
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:65)
	at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:102)

-- System Details --
Details:
	Minecraft Version: 1.15.2
	Minecraft Version ID: 1.15.2
	Operating System: Windows 10 (amd64) version 10.0
	Java Version: 1.8.0_212, Oracle Corporation
	Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
	Memory: 686121776 bytes (654 MB) / 1751646208 bytes (1670 MB) up to 3806855168 bytes (3630 MB)
	CPUs: 12
	JVM Flags: 1 total; -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump
	ModLauncher: 5.0.0-milestone.4+67+b1a340b
	ModLauncher launch target: fmluserdevclient
	ModLauncher naming: mcp
	ModLauncher services: 
		/eventbus-2.0.0-milestone.1-service.jar eventbus PLUGINSERVICE 
		/forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-launcher.jar object_holder_definalize PLUGINSERVICE 
		/forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-launcher.jar runtime_enum_extender PLUGINSERVICE 
		/accesstransformers-2.0.0-milestone.1-shadowed.jar accesstransformer PLUGINSERVICE 
		/forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-launcher.jar capability_inject_definalize PLUGINSERVICE 
		/forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-launcher.jar runtimedistcleaner PLUGINSERVICE 
		/forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-launcher.jar fml TRANSFORMATIONSERVICE 
	FML: 31.1
	Forge: net.minecraftforge:31.1.0
	FML Language Providers: 
		[email protected]
		minecraft@1
	Mod List: 
		client-extra.jar Minecraft {[email protected] DONE}
		main MacroKeys {macrokeys@NONE DONE}
		forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar Forge {[email protected] DONE}
	Launched Version: MOD_DEV
	Backend library: LWJGL version 3.2.2 build 10
	Backend API: GeForce RTX 2060/PCIe/SSE2 GL version 4.6.0 NVIDIA 446.14, NVIDIA Corporation
	GL Caps: Using framebuffer using OpenGL 3.0
	Using VBOs: Yes
	Is Modded: Definitely; Client brand changed to 'forge'
	Type: Client (map_client.txt)
	Resource Packs: 
	Current Language: English (US)
	CPU: 12x AMD Ryzen 5 3600 6-Core Processor 

This is quite annoying and I can't seem to figure out why it is erroring with this. Here is my code:
 

package mypackage;
import com.mojang.blaze3d.systems.RenderSystem;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.TranslationTextComponent;

public class GUIPunishKick extends Screen {
	private final int WIDTH = this.width;
	private final int HEIGHT = this.height;
	
	private TextFieldWidget user;
	
	public GUIPunishKick() {
		super(new TranslationTextComponent("screen.guipunishkick.spawn"));
	}
	
	@Override
	protected void init() {
		int relX = WIDTH /2;
		int relY = HEIGHT /2;
		this.user = new TextFieldWidget(font, relX + 10, relY + 10, 160, 20, null);
		user.setText("");
		user.setFocused2(true);
		user.setVisible(true);
	}
	

	protected void keyTyped(char par1, int par2) {
		super.charTyped(par1, par2);
		this.user.charTyped(par1, par2);
	}
	
	public void updateScreen() {
		this.updateScreen();
		this.user.moveCursorBy(this.user.getText().length());
	}
	
	protected void mouseClicked(int x, int y, int btn) {
		super.mouseClicked(x,  y, btn);
		this.user.mouseClicked(x, y, btn);
	}
	
	
	@Override
	public boolean isPauseScreen() {
		return false;
	}
	

	
	@Override
	public void render(int mouseX, int mouseY, float partialTicks) {
        RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
		int relX = (this.width - WIDTH) /2;
		int relY = (this.height - HEIGHT) /2;
		this.blit(relX, relY, 0, 0, WIDTH, HEIGHT);
		this.user.render(mouseX, mouseY, partialTicks);
		super.render(mouseX, mouseY, partialTicks);
	}
	
	public static void open() {
		Minecraft.getInstance().displayGuiScreen(new GUIPunishKick());
	}
}

I would appreciate if anyone could help, thanks :)

Edited by TurtlesAreHot
Posted
21 minutes ago, TurtlesAreHot said:

java.lang.NullPointerException

Hmm, I wonder where a null value is in this code.

22 minutes ago, TurtlesAreHot said:

this.user = new TextFieldWidget(font, relX + 10, relY + 10, 160, 20, null);

Ah, there it is!

 

It's not good if you make the message part of the text field widget null. The object is not nullable and requires a string, empty or not.

Posted
30 minutes ago, ChampionAsh5357 said:

Hmm, I wonder where a null value is in this code.

Ah, there it is!

 

It's not good if you make the message part of the text field widget null. The object is not nullable and requires a string, empty or not.

Ah I didn't realize I even did that. I think my editor automatically filled that in for me. Thank you it worked :)

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.