Solved Null pointer exception when getting a players balance

Discussion in 'Spigot Plugin Development' started by EvanTheSurfer, May 12, 2016.

  1. Code (Text):
    double value = Main.economy.getBalance(p) * .10;
    ???
     
  2. well we neecd more code..
     
    • Optimistic Optimistic x 1
  3. Where did you define 'economy'
     
  4. Main could be null
    economy could be null
    p could be null
    the player's balance could be null
     
  5. Not in this case. The method most likely returns a primitive which cannot be null.
     
    • Agree Agree x 1
  6. Code (Text):
        public ItemStack skull(Player p) {
           
            double value = Main.economy.getBalance(p) * .10;
           
            ItemStack skullItem = new ItemStack(Material.SKULL_ITEM);
           
            ItemMeta m = skullItem.getItemMeta();
            m.setDisplayName(p.getName()+ "'s Head");
            m.setLore(Arrays.asList(ChatColor.GREEN + "Value: " + value));
            skullItem.setItemMeta(m);
           
            return skullItem;
        }
     
  7. Your sig code is so funny. I am dying right now
     
  8. What is your error message in console? Can you show us it?
     
  9. The economy was null. Rip.

    Solved