Solved Why/How is this throwing a NullPtr?

Discussion in 'Plugin Development' started by Code0, Feb 24, 2015.

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

    Code0

    Code:
    ArrayList<Material> allContents = new ArrayList();
      for(ItemStack i : this.icontents2.get(e.getPlayer().getName())){
      allContents.add(i.getType());
      }
      for(ItemStack i : this.acontents2.get(e.getPlayer().getName())){
     LINE 16: allContents.add(i.getType()); //////////////
      }
      if(allContents.contains(e.getItemDrop().getItemStack().getType())){
      e.getPlayer().sendMessage(ChatColor.RED + "Sorry, you can't drop that when swapped.");
      e.setCancelled(true);
      Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
    @Override
    public void run() {
    e.getPlayer().updateInventory();
    }
      }, 1);
      System.out.println("cancelled normal drop");
      return;
      }
    
    So, title pretty much says it all. Line 16(marked above) throws a NullPtr error.

    this.icontents2 and this.acontents2 both are HashMap susing a string as a key (playername (yes, i'm not using uuids for this)) and an ItemStackArray as the value.

    I hope that's enough information as I simply have no idea what's going on there. :)
     
  2. Offline

    1Rogue

    I presume one (or more) of the ItemStack objects are null.
     
  3. Offline

    Code0

    That could actually be it. I got a question: Does a slot of the array get set to null if the actual item slot of the player is empty?
     
  4. Offline

    1Rogue

    Yes
     
  5. Offline

    Code0

    That clears it up. Thank you a lot.
     
Thread Status:
Not open for further replies.

Share This Page