Solved Weird gui menu glitch

Discussion in 'Plugin Development' started by xCalib0r, Jun 2, 2014.

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

    xCalib0r

    So I've made my gui menu, BUT the weirdest thing is happening. If I open up my gui and click AROUND the actual inventory I get tons of null pointer exceptions. Here's my code, what's happening wrong?

    Code:
    @EventHandler
    public void OnInventoryClick(InventoryClickEvent e) {
     
    if (!e.getInventory().equals(inv)) {
    return;
    }
     
    if (e.getWhoClicked() instanceof Player) {
    Player p = (Player) e.getWhoClicked();
     
    switch (e.getCurrentItem().getType()) {
    case APPLE:
    p.setGameMode(GameMode.CREATIVE);
    p.closeInventory();
    break;
    case CARROT
    p.setGameMode(GameMode.SURVIVAL);
    p.closeInventory();
    break;
    default:
    p.closeInventory();
    break;
    }
    }
    }
    
     
  2. Offline

    PreFiXAUT

    1. Calibor...Malte? ;D
    2. e.getCurrentItem() > Check if it is null first, othwise return. That's the once I can find for a Null-Pointer.
     
  3. Offline

    xCalib0r

    PreFiXAUT already figured it out but thanks anyways :)
     
  4. Offline

    PreFiXAUT

    Then please add a solution for Codes which might have the same problem and searched for this error and came up on this thread and/or please mark the Thread as Solved (Thread-Options > Edit Thread > Prefix (lol) > Solved)
     
Thread Status:
Not open for further replies.

Share This Page