Why am I getting "Internal error has occured" when trying to run this command.

Discussion in 'Plugin Development' started by mrdude123, Dec 30, 2015.

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


    I only get the "INTERAL ERROR" message in my chat when I try to run the command with nothing in my hand. If I hold something in my hand, it works perfectly fine.
    package plugin.thecerealkill3r.bows;
    import java.util.List;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.HumanEntity;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    public class ArtefactConversion implements CommandExecutor {
        public boolean onCommand(CommandSender sender, Command cmd, String lbl,
                String[] args) {
            Player player = (Player) sender;
            ItemStack objectinhand = ((HumanEntity) sender).getItemInHand();
            List<String> lore = player.getItemInHand().getItemMeta().getLore();
            if(player.getItemInHand() == null){
                sender.sendMessage(ChatColor.RED + "You're holding air, not an item.  Conversion failed.");
                sender.sendMessage(ChatColor.GREEN + "Material successfully converted to artefact.");
            return false;
  2. Offline


    BLIND CASTING: Check to make sure the sender is actually a player (and not the console) before casting
    MORE BLIND CASTING! If the console sent the command, how would you be able to get the item in the console's hand?

    This is your problem. You have not yet checked to see if the item in the hand is not null. If the item is null, then you are saying "Get Null's Itemmeta", which doesn't make sense, and the server would through that error. Please check if the item is null before you get the lore.
  3. Offline


    @Zombie_Striker That's not what the issue was. When I was experimenting with the lore earlier I was using that cast, but I forgot to remove it.
    When holding an item in my hand and running the command, I get a message in the chat. When holding nothing in my hand, I get an error message in my chat and a stacktrace in my console. I can give you the stacktrace if you'd like.

    Buggy code:
    if(player.getItemInHand() == null){

    sender.sendMessage(ChatColor.RED + "You're holding air, not an item. Conversion failed.");

  4. Offline


    Yes, I would like the stack trace, and I would like to see what line is causing the error (do that by reading THIS).

    The reason why I said to add a null check before getting the lore because that, if not now,it will cause an error later on. It's because even the logic behind it (as said in the previous post) would not work if the item in their hand is null.
  5. Offline


    @Zombie_Striker Here's the stacktrace. It's in the class that I showed you above, but line 46 is non-existant.

    [15:36:39 WARN]: Unexpected exception while parsing console command "convertarte
    org.bukkit.command.CommandException: Unhandled exception executing command 'conv
    ertartefact' in plugin SpecialBows vBuild4
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spi
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:18
  6. Offline


    Why're you showing those errors? Look for where the error is in your code, not where the error is in bukkit.

    And your error is most likely what @Zombie_Striker said before, either you're casting incorrectly, or your item in hand is null and you're not checking before running methods on it.

    Edit: Just read your first post again, ofcourse it's gonna throw NPE when you're not holding any item in your hand, that means your hand is null, and before you check if it's null you're calling getItemMeta on it.
Thread Status:
Not open for further replies.

Share This Page