Solved I get an NPE, however the code still works correctly.

Discussion in 'Plugin Development' started by oceantheskatr, Jan 12, 2016.

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

    oceantheskatr

    Hi, I'm checking if a clicked block is a door, and if so, execute code. It works correctly, however I get a NullPointerException, too, which is very strange.

    Here's the code for my "Events" class, which isn't much:
    http://hastebin.com/pinutudoca.avrasm

    I get an error at line 6 in the Hastebin, however in my plugin it's actually line 21. This is the only event in that class, too.

    Line: if (b.getType() != Material.WOODEN_DOOR)

    Here's the error from the log if it'll help:
    http://hastebin.com/ruqerupiqo.avrasm

    I'm sure I've just goofed on something, but I'd appreciate any help offered.
     
  2. Offline

    Zombie_Striker

    @oceantheskatr
    What if the block is Air? If the block is Air, the block will be null. If the block is null, "b.getType()" is the same as "null.getType", which would through an NPE.
     
  3. Offline

    ski23

    block is null. Do a null check. If they click air, for example, it will be null.
    Edit: @Zombie_Striker YOU BEAT ME! HOW RUDE!!!
     
  4. Offline

    oceantheskatr

    @Zombie_Striker @ski23

    Yep, changed that line to if (b == null || b.getType() != Material.WOODEN_DOOR) and it's fine now, thanks both of you :)
     
  5. Offline

    87pen

  6. Offline

    oceantheskatr

    @87pen If I had've done something like

    if (e.getAction() != Action.RIGHT_CLICK_BLOCK)
    return;

    I would've been fine I think.
     
  7. Offline

    ski23

Thread Status:
Not open for further replies.

Share This Page