NPE while getting ItemMeta

Discussion in 'Plugin Development' started by Link_Awesomesause, Jan 12, 2018.

Thread Status:
Not open for further replies.
  1. My code:
    Code:
    ItemStack is = new ItemStack(Material.ANVIL, 1);
                    System.out.println(is.getItemMeta().getDisplayName().toString());
    I get a NPE in the print statement.
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. The item-meta is null.. I used
    Code:
    System.out.println(is.getItemMeta().toString());
    Still NPE
     
  4. Offline

    Zombie_Striker

  5. @Zombie_Striker
    Getting NPE while chicking for item meta.. >_>
    Code:
    System.out.println("" + is.hasItemMeta());
     
  6. Offline

    Zombie_Striker

  7. I created the item in the previous line:
    Code:
    ItemStack is = new ItemStack(Material.ANVIL, 1);
     
  8. Offline

    Zombie_Striker

    @Link_Awesomesause
    Even still, in order for that line to be throwing an NPE, the item must be null, as nothing else should throw it on that line.
     
  9. I know that, the ItemStack gives NPE when I try
    Code:
    is.toString()
    But works if I try
    Code:
    Material m = is.getType();
    int am = is.getAmount();
    
    I've never had a problem with ItemStacks and ItemMeta before showing NPE...
    @Zombie_Striker
     
  10. Your code either accesses something null or there is a bug in Bukkit.
    Maybe the Bukkit jar file is corrupt, have you tried redownloading it?
     
  11. I think its a bug because I'm reusing old code that worked in previous version of Bukkit
     
  12. Offline

    Zombie_Striker

    @adventuretc
    The jar itself is not the problem. Then the NPE would point to itself, not some line in another plugin.

    @Link_Awesomesause
    Can you post thew full class along with the error message? There may be something else causing the problem.
     
  13. Offline

    Zombie_Striker

    @Link_Awesomesause
    And there's your problem.

    Unless there is a main plugin class somewhere else that extends JavaPlugin, it looks like you are trying to create a new process. You should not have a static main function if you want to work with bukkit.

    The reason for the NPE is because bukkit is not even running when the main method is being called. It does not even have time to set up the ItemFactory class before you attempt to use it.

    I think a better question right now is what are you intending to do?
     
  14. @Zombie_Striker
    The main method is for me to test the saving and reading of items from files, I thought that it would be a problem to run it from a main method, so I tried it on the server without a main method, same error
     
Thread Status:
Not open for further replies.

Share This Page