Solved Null pointer with displayname

Discussion in 'Plugin Development' started by Lockiller1996, Jun 13, 2020.

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

    Lockiller1996

    I have a problem with null pointer.

    if(elo[11] != null && elo[15] !=null) {
    ItemStack itemek1 = elo[11];
    ItemStack itemek2 = elo[15];
    if(itemek1.getItemMeta().hasDisplayName() && itemek2.getItemMeta().hasDisplayName()) {
    null pointer here ---> if((itemek1.getItemMeta().getDisplayName().contains("§eMagiczna Rózdzka Mocy") || itemek1.getItemMeta().getDisplayName().contains("§1Ognisty Amulet Szybkosci") || itemek1.getItemMeta().getDisplayName().contains("§6Amulet Magicznego Uzdrowienia") || itemek1.getItemMeta().getDisplayName().contains("§2Amulet Boskiej Ochrony") || itemek1.getItemMeta().getDisplayName().contains("§4Amulet Boskiego Swiatla") || itemek1.getItemMeta().getDisplayName().contains("§e§lRóg Obfitosci")) &&(itemek2.getItemMeta().getDisplayName().contains("§eMagiczna Rózdzka Mocy") || itemek2.getItemMeta().getDisplayName().contains("§1Ognisty Amulet Szybkosci") || itemek2.getItemMeta().getDisplayName().contains("§6Amulet Magicznego Uzdrowienia") || itemek2.getItemMeta().getDisplayName().contains("§2Amulet Boskiej Ochrony") || itemek2.getItemMeta().getDisplayName().contains("§4Amulet Boskiego Swiatla") || itemek2.getItemMeta().getDisplayName().contains("§e§lRóg Obfitosci"))) {
     

    Attached Files:

    • dsa.PNG
      dsa.PNG
      File size:
      44.4 KB
      Views:
      6
    Last edited: Jun 13, 2020
  2. Offline

    KarimAKL

    @Lockiller1996 Try debugging. Also, that looks like quite an if statement, you should probably shorten it for clarity.
     
    Last edited by a moderator: Jun 14, 2020
  3. Offline

    Lockiller1996

    Ok, I will try debug it. Btw. I don't have any idea how to shorten this statement. How my plugin works: When I put two Items with custom name into GUI slots. They will transform into one item (on GUI close). When I put Items without customname I got null pointer. My statement is so long because I have to check a lot of names of items
     
  4. Offline

    timtower Administrator Administrator Moderator

    KarimAKL likes this.
  5. Offline

    Lockiller1996

    Oh, I didn't think about it. Good idea.

    @timtower I added customnames to list and statement is shorter, but I can't reapir null pointer. Error occured only when I put two items without custom displayname into gui. But when I put only one, everything is okay. Variables "itemek1" and "itemek2" are slots in gui where I'm putting items to transform. variable "nazwy" is a list with customnames (like in the previous long statement). Any idea what is wrong ?
     

    Attached Files:

    • ss1.PNG
      ss1.PNG
      File size:
      67.5 KB
      Views:
      4
    • ss2.PNG
      ss2.PNG
      File size:
      16.5 KB
      Views:
      5
    Last edited by a moderator: Jun 14, 2020
  6. Offline

    caderapee

  7. Offline

    Lockiller1996

    @caderapee I added check for itemMeta and still same error ;/
     

    Attached Files:

  8. Offline

    KarimAKL

    @Lockiller1996 It doesn't seem like the error and code matches, one of them is probably outdated, try posting your current code along with an error caused by your current code.
     
  9. Offline

    Lockiller1996

    @KarimAKL you are the best :) Thanks to everyone for help
     
Thread Status:
Not open for further replies.

Share This Page