Jump to content

Recommended Posts

Posted

Hi!

 

Can someone please help me fix this NPE?

 

I've created some IEEP's that I want to sync from the server to the client for GUI rendering.  The saving on serverside works just fine (i.e. EntityConstructingEvent and changing values serverside).  After I added the PlayerJoinWorld event handler, I get an NPE on world join and am taken to the server selection screen.

 

NPE: 

[10:41:21] [Client thread/ERROR] [FML]: SimpleChannelHandlerWrapper exception
java.lang.NullPointerException
at com.mierzen.recall.ExtendedPlayer.loadNBTData(ExtendedPlayer.java:49) ~[ExtendedPlayer.class:?]
at com.mierzen.recall.packets.MessageSyncPlayerProps.handleClientSide(MessageSyncPlayerProps.java:33) ~[MessageSyncPlayerProps.class:?]
at com.mierzen.recall.packets.MessageSyncPlayerProps.handleClientSide(MessageSyncPlayerProps.java:15) ~[MessageSyncPlayerProps.class:?]
at com.mierzen.recall.packets.MessageBase.onMessage(MessageBase.java:20) ~[MessageBase.class:?]
at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:37) ~[simpleChannelHandlerWrapper.class:?]
at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:17) ~[simpleChannelHandlerWrapper.class:?]
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98) ~[simpleChannelInboundHandler.class:?]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?]
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) [MessageToMessageDecoder.class:?]
at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) [MessageToMessageCodec.class:?]
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) [DefaultChannelPipeline.class:?]
at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) [EmbeddedChannel.class:?]
at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:86) [FMLProxyPacket.class:?]
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) [NetworkManager.class:?]
at net.minecraft.client.Minecraft.runTick(Minecraft.java:2152) [Minecraft.class:?]
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1039) [Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:962) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_51]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_51]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_51]
at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_51]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?]
at GradleStart.main(Unknown Source) [start/:?] 

 

 

I am using the BaseMessage.java from MineMaarten's tutorial series http://pastebin.com/9ahZnbx9.

 

Here are my classes:

ExtendedPlayer.java http://pastebin.com/JrAhaeaJ

ExtendedPlayerHandler.java http://pastebin.com/DjmwAd3i

MessageSyncPlayerProps.java http://pastebin.com/Tp56qBVt

Posted

You're getting a NPE on this line:

NBTTagCompound properties = (NBTTagCompound)compound.getTag(EXT_PROP_NAME);

The only thing that can be null in that line is the 'compound' parameter given to the method from your message handling, and the reason that's null is because of this:

@Override
    @SideOnly(Side.CLIENT)
    public void handleClientSide(MessageSyncPlayerProps message, EntityPlayer player)
    {
        ExtendedPlayer.get(Minecraft.getMinecraft().thePlayer).loadNBTData(data);
    }

Do you see that there is a 'message' parameter in there? That's the message that was received, but you are sending 'this.data', where 'this' is now the message handler, not the message. The handler doesn't know anything about what was sent or received, and that's one of the reasons that it can be confusing putting handling methods within the message class - you expect class fields to be available, but none of them are initialized to anything.

 

You can fix your problem now by using 'message.data' as the argument to loadNBTData, but I recommend you redesign your message handling so it's more intuitive to use.

 

Something like this, where the handling calls a method on the message instance itself, rather than passing the message instance to the method, let's you use code like you originally wanted to use.

Posted

I've spent hours trying to get it fixed, but couldn't.  Thanks coolAlias, that one small change was all that was needed.

 

Thanks, I will rework the message class entirely, your's is easier to use.

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.