Solved Error when check if helmet = null

Discussion in 'Plugin Development' started by RFUDEO9EH, Mar 6, 2020.

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

    RFUDEO9EH

    code : https://pastebin.com/8xHWrqUi

    when I try to verify if helmet = null (nothing), it's doesn't work I don't no why but if I replace null by a block or a diamond helmet for exemple the plugin work correctly. I try so some thing like .equals(null), != null but nothing work. I use Java-SE 1.8 and the version of my server is 1.7.10
     
  2. Offline

    timtower Administrator Administrator Moderator

    @RFUDEO9EH Don't use getType(), then you are expecting that there is an item already.
     
  3. Offline

    RFUDEO9EH

    don't work
     
  4. Offline

    timtower Administrator Administrator Moderator

    What is the updated code?
     
  5. Offline

    RFUDEO9EH

    I just change this :

    if(p2.getInventory().getHelmet() != null){

    and I try too :

    if(p2.getInventory().getHelmet() == null){

    and :


    if(p2.getInventory().getHelmet().equals(null){
     
  6. Offline

    caderapee

  7. Offline

    RFUDEO9EH

    don't work
     
  8. Offline

    Kars

    Start printing and figure out what the value is.
     
  9. Offline

    Strahan

    It doesn't return air when there is no helmet; it returns null.

    Post the whole code, because if(p2.getInventory().getHelmet() != null){ will fix it. If it isn't working, something else is awry.
     
  10. Offline

    RFUDEO9EH

    https://pastebin.com/Wwrvy3tm
     
  11. Offline

    timtower Administrator Administrator Moderator

    You are first checking the type for TNT, then you do a null check.
    Code order is important.
    Stack trace will also tell which line is causing the error, can be used to narrow the problem down to a single place
     
  12. Offline

    RFUDEO9EH

    SOLVED TY
     
Thread Status:
Not open for further replies.

Share This Page