Solved Getting a weird NPE

Discussion in 'Spigot Plugin Development' started by SpiroMarshes, Jun 23, 2016.

  1. Getting an odd NPE error. Trying to cancel crop breaking. Here is my method:

    Code (Text):
        public void onEntityInteract(PlayerInteractEvent event)
            if (event.getClickedBlock().getType().equals(Material.SOIL) && event.getAction().equals(Action.PHYSICAL))
    Here is the error:
  2. What is on line 39?
  3. event.getClickedBlock() is null if the action isn't block-based. You're checking that first, which is throwing NPEs.
  4. So I should change my if statement to
    Code (Text):
    if (event.getAction().equals(Action.PHYSICAL) && event.getClickedBlock().getType().equals(Material.SOIL)  )
  5. Fixed it, thanks.