An impossible NPE [getInventory()]?

Discussion in 'Plugin Development' started by x2nec, Jul 1, 2014.

Thread Status:
Not open for further replies.
  1. So to summarise, I have a code snippet beneath, for checking if the players inventory is empty. I have checked if the player object is null - it is not, the name prints correctly. The error occurs when I do p.getInventory().

    Code:java
    1. public boolean hasEmptyInventory(Player p) {
    2. System.out.println(p.getName());
    3. if(p.getInventory().getArmorContents() == null && p.getInventory().getContents() == null){
    4. return true;
    5. }
    6. return false;
    7. }


    The error definitely occurs with p.getInventory() and I just cannot seem to find the problem, been looking for a few hours now. ([Craft]Bukkit 1.7.9 for reference, latest builds).
     
  2. Offline

    hankered

    Wrong section dude :p
     
  3. :/ It's given me a headache :p (Moderator: Could it be moved please?)
     
  4. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    x2nec WHEEEEEE moved!
    hankered Just report threads in the wrong section, and we'll get to them :)
     
  5. Offline

    Rocoty

    x2nec It does not occur at p.getInventory(). It cannot possibly occur there. Because p is not null and cannot possibly be so at that point in the code. However, what could throw an NPE is the call to .getArmorContents() or .getContents(), since the inventory might be null. Although, this seems unlikely as well, seeing as a Player usually always has an Inventory.

    I would suggest making absolutely sure you are running the latest version of your plugin by rebuilding and uploading the new version to your server, run that and read the new stack trace. If you are still stuck after that, upload the updated code and stack trace.
     
  6. Offline

    agent6262

    Could you provide code where this method is called.
     
    1Rogue likes this.
Thread Status:
Not open for further replies.

Share This Page