zombiekiller222 Posted October 14, 2012 Posted October 14, 2012 Java throws a java.lang.NullPointerException when I try to use player.openGui(LotrCraft.Instance, 1, world, x, y, z); Doing a little stack-following I found it happens when this code is ran: FMLCommonHandler.instance().showGuiScreen(handler.getClientGuiElement(modGuiId, player, world, x, y, z)); So, presumably, my gui handler is returning null? Here is it's code: package mymod.common; import cpw.mods.fml.common.network.IGuiHandler; import net.minecraft.src.*; public class GuiHandler implements IGuiHandler { @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { switch (ID) { case 1: return new ContainerSmelter(player.inventory, world, x, y, z); } return null; } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { switch (ID) { case 1: return new GuiSmelter(player.inventory, world, x, y, z); } return null; } } If you need the code for the container and gui, i'll post it. Quote
PCChazter Posted October 15, 2012 Posted October 15, 2012 Do you have public static GuiHandler guiHandler = new GuiHandler(); and NetworkRegistry.instance().registerGuiHandler(this, guiHandler); added to your main mod file? Quote
zombiekiller222 Posted October 15, 2012 Author Posted October 15, 2012 Yes, I do. I did some work and replaced some of mc's code, and now it works: //FMLCommonHandler.instance().showGuiScreen(handler.getClientGuiElement(modGuiId, player, world, x, y, z)); FMLCommonHandler.instance().showGuiScreen(new plantony.lotrcraft.common.GuiHandler().getClientGuiElement(modGuiId, player, world, x, y, z)); I don't want it to be like this in the long run (creates incompatibilities). Quote
PCChazter Posted October 15, 2012 Posted October 15, 2012 I see, that "handler" variable looks like it should be taken from a List that should have the mod/IGuiHandler relations in it, and NetworkRegistry.instance().registerGuiHandler(this, guiHandler); should have populated it correctly. it giving you a null pointer exception means it was not put in properly. Can you post your main mod file, and the item/block that calls the Gui? Maybe I can see something, maybe not, but I'll give it a shot. Also, make sure you have the latest "recommended" build of Forge, there's always useful updates. Quote
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.