Solved NullPointException e.getInventory().getItem() (InventoryClickEvent)

Discussion in 'Plugin Development' started by unityself, Feb 13, 2014.

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

    unityself

    This doesnt work:
    Code:java
    1. for(int i = 0;i != 8;i++){
    2. /*NullPointException*/switch(e.getInventory().getItem(i).getTypeId()){
    3. //doing something...
    4. }
    5. }

    I want to check every Item in the Inventory, but I got a NullPointException.

    Can someone help me?
     
  2. Offline

    JRL1004

    unityself Add a null check
    Code:
    for(int i = 0;i != 8;i++){
    if(e.getInventory().getItem(i) == null) continue;
    switch(e.getInventory().getItem(i).getTypeId()){
    //doing something...
    }
    }
     
  3. Offline

    unityself

Thread Status:
Not open for further replies.

Share This Page