CraftInventory.java line 60: NullPointerException

Discussion in 'Plugin Development' started by subanoomic, Sep 7, 2012.

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

    subanoomic

    Hi everyone,

    I want to restore chest contents under certain circumstances. For doing this, I have a Map<Block, ItemStack[]> chestContents that maps blocks to ItemStack arrays containing the content of the chest.

    The storing seems to work fine. However, there is a problem when restoring the contents. Here is the code I use for this:

    Code:
    Set<Block> chestBlocks = chestContents.keySet();
    for (Block cb : chestBlocks) {
        BlockState st = cb.getState();
        if (st instanceof Chest) {
            Chest ch = (Chest) st;
            if (ch != null) {
                if (ch.getInventory() != null && chestContents.get(cb) != null) {
                    ch.getInventory().setContents(chestContents.get(cb));
                }
            }
        }
    }
    
    The problem is that line 8 causes a null pointer exception in CraftInventory.java (https://github.com/Bukkit/CraftBukk...kit/craftbukkit/inventory/CraftInventory.java) on line 60:

    Here is line 60 of that file:
    Code:
    if (getInventory().getContents().length < items.length) {
    
    What could cause this? What is null here?

    Thanks in advance for your answers!

    Daniel
     
  2. Offline

    Timr

    You're reading your stack trace improperly, please post it in its entirety so that we can try to get to the root of the problem.
     
Thread Status:
Not open for further replies.

Share This Page