Minecraft crashes when I open my GUI

Section

Did you just make your perfect GUI and wanted to test it out in Minecraft. You right click and the game crashes.

The crash log usually contains the following lines:

java.lang.ArrayIndexOutOfBoundsException: [some number]
    at java.util.Arrays$ArrayList.get(Arrays.java:3841)
    at net.minecraft.util.NonNullList.get(NonNullList.java:51)
    at mod.mcreator.mcreator_runeInfuser$TileEntityCustom.getStackInSlot(YOURGUI.java:177)
    at net.minecraft.inventory.Slot.getStack(Slot.java:81)
    at net.minecraft.inventory.Container.detectAndSendChanges(Container.java:97)
    at net.minecraft.entity.player.EntityPlayerMP.onUpdate(EntityPlayerMP.java:365)
    at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2171)
    at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:871)
    at net.minecraft.world.World.updateEntity(World.java:2130)
    at net.minecraft.world.WorldServer.tickPlayers(WorldServer.java:672)
    at net.minecraft.world.World.updateEntities(World.java:1906)
    at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:643)
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:842)
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743)
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592)
    at java.lang.Thread.run(Thread.java:748)

This happens when you want to access the slot of the block GUI is bound to that does not exist in the block.

If you set inventory size of the block your GUI is bound to say 10, this means your block has 10 slots. This means that you can use slots from ID 0 to ID 9 (slot IDs start with 0). If you use slot bound to inherited inventory and use ID 10 in our case, you will get this kind of crash where [some number] will be 10.

Rule of thumb

If you want to make sure that your GUI does not crash, make sure to set the inventory size of the block you GUI is bound to at least for one number larger than the biggest ID of the slot in your GUI.



Donate to MCreator

By donating to developers you can speed up development, as with more resources, we can dedicate more time to MCreator. It is a free project made by developers working on it in their free time.