Failed to handle packet: NPE

Discussion in 'Plugin Development' started by np98765, Sep 23, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    np98765

    All I'm doing is going through all 35 slots and setting items. It'll go through all 35, and then I'll be kicked for "Internal server error".

    Code:
    11:11:23 [WARNING] Failed to handle packet: java.lang.NullPointerException
    java.lang.NullPointerException
    at net.minecraft.server.ItemStack.a(ItemStack.java:268)
    at net.minecraft.server.PlayerInventory.k(PlayerInventory.java:167)
    at net.minecraft.server.EntityHuman.d(EntityHuman.java:303)
    at net.minecraft.server.EntityLiving.h_(EntityLiving.java:447)
    at net.minecraft.server.EntityHuman.h_(EntityHuman.java:158)
    at net.minecraft.server.EntityPlayer.g(EntityPlayer.java:203)
    at net.minecraft.server.NetServerHandler.d(NetServerHandler.java:128)
    at net.minecraft.server.ServerConnection.b(SourceFile:35)
    at net.minecraft.server.DedicatedServerConnection.b(SourceFile:30)
    at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:583)
    at net.minecraft.server.DedicatedServer.q(DedicatedServer.java:212)
    at net.minecraft.server.MinecraftServer.p(MinecraftServer.java:476)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:408)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    
     
  2. Offline

    Infamous Jeezy

    We need to see line 268 of ItemStack.java
     
  3. Offline

    np98765

    ... That's not mine. :p

    at net.minecraft.server.ItemStack...
     
  4. Offline

    Infamous Jeezy

    Oops, I should have realized that.
    Well something is being set to null where it should not be.
    We can't really tell without seeing the code that's causing the problem.
     
  5. Offline

    np98765

    Ah, ok! That should solve my problem, considering that this happened when I was trying to set slots to null... I guess it's supposed to be Material.AIR, then.

    Let me do some testing; thanks!

    Nope, still get it. And I thought null meant an empty slot? Let me do some more testing and trying.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  6. Offline

    Infamous Jeezy

    It may not be because your setting a slot to null, it could be something else that is inconspicuous.
    I'm pretty sure the stack trace should point you to the error.
    Try posting the whole stack trace.
     
  7. Offline

    np98765

    That is the entire stack trace...
    Code:
    [WARNING] Failed to handle packet: java.lang.NullPointerException
    java.lang.NullPointerException
    at net.minecraft.server.ItemStack.a(ItemStack.java:268)
    at net.minecraft.server.PlayerInventory.k(PlayerInventory.java:167)
    at net.minecraft.server.EntityHuman.d(EntityHuman.java:303)
    at net.minecraft.server.EntityLiving.h_(EntityLiving.java:447)
    at net.minecraft.server.EntityHuman.h_(EntityHuman.java:158)
    at net.minecraft.server.EntityPlayer.g(EntityPlayer.java:203)
    at net.minecraft.server.NetServerHandler.d(NetServerHandler.java:128)
    at net.minecraft.server.ServerConnection.b(SourceFile:35)
    at net.minecraft.server.DedicatedServerConnection.b(SourceFile:30)
    at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:583)
    at net.minecraft.server.DedicatedServer.q(DedicatedServer.java:212)
    at net.minecraft.server.MinecraftServer.p(MinecraftServer.java:476)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:408)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    
    No line number or anything :'(
     
  8. Offline

    brord

    plugin incompatibility?
     
  9. Offline

    np98765

    That's a good thought, but I've tested it on my dev server without any other plugins.

    Infamous Jeezy
    brord

    I've isolated the problem line:

    Code:
     
     String[] s = getSlot.split(" ");
    String[] item = s[0].split(":");
     
    //PROBLEM LINE:
    i.setTypeId(Integer.parseInt(item[0]));
    
    It prints everything to the console correctly, and gives the items correctly -- The only issue is the error and the user being disconnected for "Internal server error".

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  10. I suppose you are setting the item to an "ItemStack with the id 0", which is technically invalid and leads to bad stuff.
    Instead, you need to actually set it to null, I think.

    If I recall correctly, this works:
    Code:
    someInventory.setSlot(slot, null); // clears the slot
    ... and this doesn't:
    Code:
    someInventory.setSlot(slot, [ItemStack with id 0]); // goes BOOM
    It appears to me that that's what you are doing.
     
  11. Offline

    np98765

    Bone008
    This is what I'm doing if the config says 0

    Code:
    for (slot = 0; slot<=35; slot++) {
      if (getConfig().getString(items." + slot).equals("0")) {
      p.getInventory().setItem(slot, null);
    }
    
    firecopy
    You've helped me numerous times in the past :) ... Any ideas? :confused:

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
Thread Status:
Not open for further replies.

Share This Page