Solved Illogic NullPointerException

Discussion in 'Plugin Development' started by CollidedMoon, May 9, 2015.

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

    CollidedMoon

    Hey guys!
    I'm having trouble using a player name!
    Here is the code:
    Code:
                else if (player.getItemInHand().getType() == Material.COMMAND) {
                    Inventory optionInv = Bukkit.createInventory(player, 36, ChatColor.YELLOW + "Options");
                    short damage;
                   
                    //FRIENDS
                    player.sendMessage(pname);
                    if(HubMain.api.isResieveInvitations(pname))
                        damage = 10;
                    else
                        damage = 8;
                    Menu.createDisplayWithDamage(Material.RED_ROSE, 1,(short) 4, optionInv, 10, ChatColor.GOLD + "Recevoir les invitations d'amis", null, null, null);
                    Menu.createDisplayWithDamage(Material.INK_SACK, 1, damage, optionInv, 19, "", null, null, null);
                   
                    //MESSAGES
                    if(HubMain.api.isResieveMessages(pname))
                        damage = 10;
                    else
                        damage = 8;
                    Menu.createDisplayWithDamage(Material.PAPER, 1,(short) 0, optionInv, 12, ChatColor.GOLD + "Recevoir les messages", null, null, null);
                    Menu.createDisplayWithDamage(Material.INK_SACK, 1, damage, optionInv, 21, "", null, null, null);
               
                    //MESSAGES
                    if(HubMain.api.isResieveParty(pname))
                        damage = 10;
                    else
                        damage = 8;
                    Menu.createDisplayWithDamage(Material.BOOK_AND_QUILL, 1,(short) 0, optionInv, 14, ChatColor.GOLD + "Recevoir les invitations de party", null, null, null);
                    Menu.createDisplayWithDamage(Material.INK_SACK, 1, damage, optionInv, 23, "", null, null, null);
               
                    //PLAYERS
                    if(!Menu.hiddenPlayers.contains(player))
                        damage = 10;
                    else
                        damage = 8;
                    Menu.createDisplayWithDamage(Material.EYE_OF_ENDER, 1,(short) 0, optionInv, 16, ChatColor.GOLD + "Afficher les joueurs", null, null, null);
                    Menu.createDisplayWithDamage(Material.INK_SACK, 1, damage, optionInv, 25, "", null, null, null);
               
                    player.openInventory(optionInv);            }
            }
    I have a NullPointerException at line 7, but the player name is sent to the player.
    What is the problem?
     
  2. @CollidedMoon I suggest you read this, so that your code will be a little more understandable. Also: what line is line 7? It's kind of hard to tell.
     
  3. Offline

    CollidedMoon

    @Datdenkikniet
    Line 7 is "if(HubMain.api.isResieveInvitations(pname))"
    Basicly, it checks if the player has activated friend invitations.
    Sorry for not being clear.
     
  4. Online

    timtower Administrator Administrator Moderator

    Datdenkikniet likes this.
  5. Offline

    CollidedMoon

    @timtower Oh my god, just forgot to init the API! Thanks!
     
  6. Online

    timtower Administrator Administrator Moderator

Thread Status:
Not open for further replies.

Share This Page