Jump to content

Recommended Posts

Posted

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.

Posted

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).

Posted

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.

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.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.