Solved Error: Item cannot be null

Discussion in 'Plugin Development' started by Akilogramofstone, Nov 10, 2021.

Thread Status:
Not open for further replies.
  1. Hey, so I'm a beginner at this so this might be dumb, but I was making a custom command that gives a custom item and then I saw this error in my server logs. Any ideas how to fix it?

    [20:19:06 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'magicwand' in plugin MegaPlugin v0.1.3
            at org.bukkit.command.PluginCommand.execute( ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.command.SimpleCommandMap.dispatch( ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand( ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand( [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.PlayerConnection.a( [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a( [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat.a( [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$ [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at java.base/java.util.concurrent.Executors$ [?:?]
            at java.base/ [?:?]
            at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.B( [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B( [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A( [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at [spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at java.base/ [?:?]
    Caused by: java.lang.IllegalArgumentException: Item cannot be null
            at org.apache.commons.lang.Validate.noNullElements( ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.inventory.CraftInventory.addItem( ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at me.deluck1est.megaplugin.commands.WandCommand.onCommand( ~[?:?]
            at org.bukkit.command.PluginCommand.execute( ~[spigot-1.8.8.jar:git-Spigot-db6de12-18fbb24]
            ... 15 more
  2. Online

    timtower Administrator Administrator Moderator

    Caused by: java.lang.IllegalArgumentException: Item cannot be null
    Seems pretty clear to me.
  3. Offline


    Stack traces usually tell you everything you need to know. Do me a favor and learn reading them. And without knowing your code we can't help you anyways just by looking at the error.
  4. So, I'm guessing the error is caused by class "WandCommand" at line 19?

    package me.deluck1est.megaplugin.commands;
    import me.deluck1est.megaplugin.CustomItems;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    public class WandCommand implements CommandExecutor {
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            if (command.getName().equalsIgnoreCase("magicwand")) {
                if (sender instanceof Player) {
                    Player player = (Player) sender;
                    if (sender.isOp()) {
                        player.sendMessage(ChatColor.GOLD + "Successfully gave " + ChatColor.GRAY + player.getDisplayName() + ChatColor.GOLD + " " + CustomItems.wand.getAmount() + ChatColor.AQUA + " Magic Wand" + ChatColor.GOLD + ".");
            return true;
  5. Online

    timtower Administrator Administrator Moderator

  6. Offline


    Check if customitem.wand is null and it is that's the reason you're getting an error.
  7. I don't think it is, though.
    package me.deluck1est.megaplugin;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.inventory.ItemFlag;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import java.util.ArrayList;
    import java.util.List;
    public class CustomItems {
        public static ItemStack wand;
        public static void init() {
        private static void createWand() {
            ItemStack item = new ItemStack(Material.STICK, 1);
            ItemMeta meta = item.getItemMeta();
            List<String> lore = new ArrayList<>();
            meta.setDisplayName(ChatColor.AQUA + "Magic Wand");
            lore.add(ChatColor.ITALIC + "" + ChatColor.GRAY + "launch");
            meta.addEnchant(Enchantment.KNOCKBACK, 1, false);
            wand = item;
  8. Online

    timtower Administrator Administrator Moderator

  9. Well, I don't understand what the init function does. I just followed a tutorial on how to do it.
  10. Online

    timtower Administrator Administrator Moderator

    @Akilogramofstone It makes "wand" to stop being null.
    So you need to call it once.
  11. Thanks for the help, it worked!
Thread Status:
Not open for further replies.

Share This Page