Jump to content

[SOLVED][1.13.2]I wanted to create a GUI Button but it gave me the null pointer error


Recommended Posts

Posted (edited)
@Override
protected void initGui() {
    this.buttons.clear();
    this.buttons.add(this.buttonOk = new GuiButton(0, this.width / 2, this.height - buttonOk.height / 2,"Ok")
    {
        @Override
        public void onClick(double p_194829_1_, double p_194829_3_) {
            super.onClick(p_194829_1_, p_194829_3_);
        }
    });
    super.initGui();
}

This code is in my custom Gui which is a subclass of GuiScreen

 

This error happens when I entered my world

Spoiler

[20:28:40.340] [Server thread/INFO] [minecraft/MinecraftServer]: Test joined the game
[20:28:40.606] [Server thread/ERROR] [minecraft/MinecraftServer]: Encountered an unexpected exception
net.minecraft.crash.ReportedException: Ticking memory connection
    at net.minecraft.network.NetworkSystem.tick(NetworkSystem.java:140) ~[?:?]
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:769) ~[?:?]
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:669) ~[?:?]
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:115) ~[?:?]
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:565) [?:?]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_202]
Caused by: java.lang.NullPointerException
    at com.yuckyh.equisora.client.gui.GuiClassSelect.initGui(GuiClassSelect.java:28) ~[classes/:?]
    at net.minecraft.client.gui.GuiScreen.setWorldAndResolution(GuiScreen.java:310) ~[forge-1.13.2-25.0.76_mapped_snapshot_20180921-1.13.jar:?]
    at net.minecraft.client.Minecraft.displayGuiScreen(Minecraft.java:707) ~[forge-1.13.2-25.0.76_mapped_snapshot_20180921-1.13.jar:?]
    at com.yuckyh.equisora.event.PlayerEventHandlers.onPlayerLoggedin(PlayerEventHandlers.java:18) ~[classes/:?]
    at net.minecraftforge.eventbus.ASMEventHandler_1_PlayerEventHandlers_onPlayerLoggedin_PlayerLoggedInEvent.invoke(.dynamic) ~[?:?]
    at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:80) ~[eventbus-0.8.0-service.jar:?]
    at net.minecraftforge.eventbus.EventBus.post(EventBus.java:257) ~[eventbus-0.8.0-service.jar:?]
    at net.minecraftforge.fml.hooks.BasicEventHooks.firePlayerLoggedIn(BasicEventHooks.java:54) ~[?:?]
    at net.minecraft.server.management.PlayerList.initializeConnectionToPlayer(PlayerList.java:190) ~[?:?]
    at net.minecraft.network.NetHandlerLoginServer.tryAcceptPlayer(NetHandlerLoginServer.java:113) ~[?:?]
    at net.minecraft.network.NetHandlerLoginServer.tick(NetHandlerLoginServer.java:64) ~[?:?]
    at net.minecraft.network.NetworkManager.tick(NetworkManager.java:233) ~[?:?]
    at net.minecraft.network.NetworkSystem.tick(NetworkSystem.java:134) ~[?:?]
    ... 5 more
[20:28:42.293] [Server thread/ERROR] [minecraft/MinecraftServer]: This crash report has been saved to: C:\Users\Admin\Desktop\Forge Mod\Equisora\run\.\crash-reports\crash-2019-03-12_20.28.40-server.txt
[20:28:42.299] [Server thread/INFO] [minecraft/MinecraftServer]: Stopping server
[20:28:42.300] [Server thread/INFO] [minecraft/MinecraftServer]: Saving players
[20:28:44.505] [Server thread/INFO] [minecraft/NetHandlerPlayServer]: Test lost connection: Internal Exception: java.lang.StackOverflowError
[20:28:44.506] [Server thread/INFO] [minecraft/MinecraftServer]: Test left the game
[20:28:44.533] [Server thread/INFO] [minecraft/NetHandlerPlayServer]: Stopping singleplayer server as player logged out
[20:28:44.570] [Server thread/INFO] [minecraft/MinecraftServer]: Saving worlds
[20:28:44.570] [Server thread/INFO] [minecraft/MinecraftServer]: Saving chunks for level 'New World'/minecraft:overworld
[20:28:44.629] [Server thread/DEBUG] [ne.mi.fm.FMLWorldPersistenceHook/WP]: Gathering id map for writing to world save New World
---- Minecraft Crash Report ----
// I let you down. Sorry :(

Time: 3/12/19 8:28 PM
Description: Ticking memory connection

java.lang.NullPointerException: Ticking memory connection
    at com.yuckyh.equisora.client.gui.GuiClassSelect.initGui(GuiClassSelect.java:28)
    at net.minecraft.client.gui.GuiScreen.setWorldAndResolution(GuiScreen.java:310)
    at net.minecraft.client.Minecraft.displayGuiScreen(Minecraft.java:707)
    at com.yuckyh.equisora.event.PlayerEventHandlers.onPlayerLoggedin(PlayerEventHandlers.java:18)
    at net.minecraftforge.eventbus.ASMEventHandler_1_PlayerEventHandlers_onPlayerLoggedin_PlayerLoggedInEvent.invoke(.dynamic)
    at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:80)
    at net.minecraftforge.eventbus.EventBus.post(EventBus.java:257)
    at net.minecraftforge.fml.hooks.BasicEventHooks.firePlayerLoggedIn(BasicEventHooks.java:54)
    at net.minecraft.server.management.PlayerList.initializeConnectionToPlayer(PlayerList.java:190)
    at net.minecraft.network.NetHandlerLoginServer.tryAcceptPlayer(NetHandlerLoginServer.java:113)
    at net.minecraft.network.NetHandlerLoginServer.tick(NetHandlerLoginServer.java:64)
    at net.minecraft.network.NetworkManager.tick(NetworkManager.java:233)
    at net.minecraft.network.NetworkSystem.tick(NetworkSystem.java:134)
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:769)
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:669)
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:115)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:565)
    at java.lang.Thread.run(Thread.java:748)


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

-- Head --
Thread: Client thread
Stacktrace:
    at com.yuckyh.equisora.client.gui.GuiClassSelect.initGui(GuiClassSelect.java:28)
    at net.minecraft.client.gui.GuiScreen.setWorldAndResolution(GuiScreen.java:310)
    at net.minecraft.client.Minecraft.displayGuiScreen(Minecraft.java:707)
    at com.yuckyh.equisora.event.PlayerEventHandlers.onPlayerLoggedin(PlayerEventHandlers.java:18)
    at net.minecraftforge.eventbus.ASMEventHandler_1_PlayerEventHandlers_onPlayerLoggedin_PlayerLoggedInEvent.invoke(.dynamic)
    at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:80)
    at net.minecraftforge.eventbus.EventBus.post(EventBus.java:257)
    at net.minecraftforge.fml.hooks.BasicEventHooks.firePlayerLoggedIn(BasicEventHooks.java:54)
    at net.minecraft.server.management.PlayerList.initializeConnectionToPlayer(PlayerList.java:190)
    at net.minecraft.network.NetHandlerLoginServer.tryAcceptPlayer(NetHandlerLoginServer.java:113)
    at net.minecraft.network.NetHandlerLoginServer.tick(NetHandlerLoginServer.java:64)
    at net.minecraft.network.NetworkManager.tick(NetworkManager.java:233)

-- Ticking connection --
Details:
    Connection: net.minecraft.network.NetworkManager@25f1315b
Stacktrace:
    at net.minecraft.network.NetworkSystem.tick(NetworkSystem.java:134)
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:769)
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:669)
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:115)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:565)
    at java.lang.Thread.run(Thread.java:748)

-- System Details --
Details:
    Minecraft Version: 1.13.2
    Operating System: Windows 10 (amd64) version 10.0
    Java Version: 1.8.0_202, Oracle Corporation
    Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
    Memory: 234799752 bytes (223 MB) / 600309760 bytes (572 MB) up to 934281216 bytes (891 MB)
    JVM Flags: 1 total; -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump
    FML: New FML!
    Loaded coremods (and transformers): Nothing
    Profiler Position: N/A (disabled)
    Player Count: 1 / 8; [EntityPlayerMP['Test'/82, l='New World', x=-136.50, y=74.00, z=-119.50]]
    Data Packs: vanilla, mod:forge, mod:equisora
    Type: Integrated Server (map_client.txt)
    Is Modded: Definitely; Client brand changed to 'forge'
#@!@# Game crashed! Crash report saved to: #@!@# .\crash-reports\crash-2019-03-12_20.28.40-server.txt
[20:28:45.377] [Client Shutdown Thread/INFO] [minecraft/MinecraftServer]: Stopping server
[20:28:45.379] [Client Shutdown Thread/INFO] [minecraft/MinecraftServer]: Saving players
[20:28:45.379] [Client Shutdown Thread/INFO] [minecraft/MinecraftServer]: Saving worlds
[20:28:45.380] [Client Shutdown Thread/INFO] [minecraft/MinecraftServer]: Saving chunks for level 'New World'/minecraft:overworld
[20:28:45.380] [Thread-4/FATAL] [ne.mi.fm.pa.ModFileResourcePack/]: Failed to clean up tempdir C:\Users\Admin\AppData\Local\Temp\modpacktmp8290204505741227786
[20:28:45.381] [Client Shutdown Thread/DEBUG] [ne.mi.fm.FMLWorldPersistenceHook/WP]: Gathering id map for writing to world save New World
AL lib: (EE) alc_cleanup: 1 device not closed

Process finished with exit code -1

I was wondering why declaring a new GuiButton instance give me a null pointer error

Edited by yuckyh
Putting bunch of code/log to a spoiler to improve readibility
Posted (edited)

1. Use the spoiler to post big bunch of code/log.

2. 

5 minutes ago, yuckyh said:

at com.yuckyh.equisora.client.gui.GuiClassSelect.initGui(GuiClassSelect.java:28) ~[classes/:?]

Something at line 28 is null. Figure it out.

 

Hint:

Spoiler

You’ve never instantiated the button.

 

Edited by DavidM

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Posted

 
Spoiler

package com.yuckyh.equisora.client.gui;

import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;

public class GuiClassSelect extends GuiScreen
{
    private int guiWidth = 800;
    private int guiHeight = 450;
    private int guiCenterX = (this.width/2) - guiWidth/2;
    private int guiCenterY = (this.height/2) - guiHeight/2;

    @Override
    public void render(int mouseX, int mouseY, float partialTicks)
    {
        drawDefaultBackground();
        super.render(mouseX, mouseY, partialTicks);
    }

    @Override
    protected void initGui() {
        GuiButton buttonOk = new GuiButton(0, this.width / 2 - width, this.height*5/6,"Ok")
        {
            @Override
            public void onClick(double p_194829_1_, double p_194829_3_) {
                super.onClick(p_194829_1_, p_194829_3_);
            }
        };
        this.buttons.add(buttonOk);
        super.initGui();
    }

    @Override
    public boolean doesGuiPauseGame() {
        return true;
    }
}

My Gui class

 

The null pointer exception is gone, but my button never appeared in the gui screen

Posted
On 3/12/2019 at 10:12 PM, diesieben07 said:

You must first call super.initGui before adding your buttons.

package com.yuckyh.equisora.client.gui;

import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;

public class GuiClassSelect extends GuiScreen
{
    private int guiWidth = 800;
    private int guiHeight = 450;
    private int guiCenterX = (this.width/2) - guiWidth/2;
    private int guiCenterY = (this.height/2) - guiHeight/2;

    @Override
    public void render(int mouseX, int mouseY, float partialTicks)
    {
        super.render(mouseX, mouseY, partialTicks);
    }

    @Override
    protected void initGui() {
        super.initGui();
        GuiButton buttonOk = new GuiButton(0, this.width / 2 - width, this.height * 5 / 6, "Ok") {
            @Override
            public void onClick(double p_194829_1_, double p_194829_3_) {
                super.onClick(p_194829_1_, p_194829_3_);
            }
        };
        this.buttons.add(buttonOk);
    }

    @Override
    public boolean doesGuiPauseGame() {
        return true;
    }
}

Is it like that? if it is, it didn't work

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.