java.lang.ExceptionInInitializerError

Discussion in 'Plugin Development' started by nelson2tm, Jul 2, 2014.

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

    nelson2tm

    I am making a plugin with should give you techinical blocks via a gui. But when i try to run it, it won't start up!
    Console error (open)

    Code:
    [21:31:21 ERROR]: Could not load 'plugins\CreativeInventory.jar' in folder 'plug
    ins'
    org.bukkit.plugin.InvalidPluginException: java.lang.ExceptionInInitializerError
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:131) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-65-gd550f2f-b3077jnks]
            at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.
    java:328) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-65-gd550f2f-b3077jnks]
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager
    .java:251) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-65-gd550f2f-b3077jnks]
            at org.bukkit.craftbukkit.v1_7_R3.CraftServer.loadPlugins(CraftServer.ja
    va:357) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-65-gd550f2f-b3077jnks]
            at org.bukkit.craftbukkit.v1_7_R3.CraftServer.reload(CraftServer.java:79
    9) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-65-gd550f2f-b3077jnks]
            at org.bukkit.Bukkit.reload(Bukkit.java:288) [craftbukkit.jar:git-Bukkit
    -1.7.2-R0.3-65-gd550f2f-b3077jnks]
            at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:
    23) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-65-gd550f2f-b3077jnks]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:18
    0) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-65-gd550f2f-b3077jnks]
            at org.bukkit.craftbukkit.v1_7_R3.CraftServer.dispatchCommand(CraftServe
    r.java:703) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-65-gd550f2f-b3077jnks]
            at net.minecraft.server.v1_7_R3.PlayerConnection.handleCommand(PlayerCon
    nection.java:955) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-65-gd550f2f-b3077jnks]
            at net.minecraft.server.v1_7_R3.PlayerConnection.a(PlayerConnection.java
    :817) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-65-gd550f2f-b3077jnks]
            at net.minecraft.server.v1_7_R3.PacketPlayInChat.a(PacketPlayInChat.java
    :28) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-65-gd550f2f-b3077jnks]
            at net.minecraft.server.v1_7_R3.PacketPlayInChat.handle(PacketPlayInChat
    .java:47) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-65-gd550f2f-b3077jnks]
            at net.minecraft.server.v1_7_R3.NetworkManager.a(NetworkManager.java:157
    ) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-65-gd550f2f-b3077jnks]
            at net.minecraft.server.v1_7_R3.ServerConnection.c(SourceFile:134) [craf
    tbukkit.jar:git-Bukkit-1.7.2-R0.3-65-gd550f2f-b3077jnks]
            at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:6
    67) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-65-gd550f2f-b3077jnks]
            at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:2
    60) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-65-gd550f2f-b3077jnks]
            at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:5
    58) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-65-gd550f2f-b3077jnks]
            at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java
    :469) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-65-gd550f2f-b3077jnks]
            at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:6
    28) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-65-gd550f2f-b3077jnks]
    Caused by: java.lang.ExceptionInInitializerError
            at java.lang.Class.forName0(Native Method) ~[?:1.7.0_55]
            at java.lang.Class.forName(Unknown Source) ~[?:1.7.0_55]
            at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.jav
    a:40) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-65-gd550f2f-b3077jnks]
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:127) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-65-gd550f2f-b3077jnks]
            ... 19 more
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 18
            at org.bukkit.craftbukkit.v1_7_R3.inventory.CraftInventoryCustom$Minecra
    ftInventory.setItem(CraftInventoryCustom.java:103) ~[craftbukkit.jar:git-Bukkit-
    1.7.2-R0.3-65-gd550f2f-b3077jnks]
            at org.bukkit.craftbukkit.v1_7_R3.inventory.CraftInventory.setItem(Craft
    Inventory.java:82) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-65-gd550f2f-b3077jnks
    ]
            at me.nelson2tm.creativeinventory.CreativeInventory.<clinit>(CreativeInv
    entory.java:60) ~[?:?]
            at java.lang.Class.forName0(Native Method) ~[?:1.7.0_55]
            at java.lang.Class.forName(Unknown Source) ~[?:1.7.0_55]
            at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.jav
    a:40) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-65-gd550f2f-b3077jnks]
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:127) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-65-gd550f2f-b3077jnks]
            ... 19 more

    Code (open)

    Code:
        package me.nelson2tm.creativeinventory;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
         
        public class CreativeInventory extends JavaPlugin implements Listener {
         
        public void onEnable(){
        getLogger().info("Enabled!");
        getServer().getPluginManager().registerEvents(this, this);
        }
         
        public void onDisable(){
        getLogger().info("Disabled!");
        }
        
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            if(!(sender instanceof Player)){
                sender.sendMessage("[CreativeInventory] You can only use this command as player!");
                return true;
                }
        Player player = (Player) sender;
        if(cmd.getName().equalsIgnoreCase("creativeinventory")){
            player.openInventory(menu);
            }
        return false;
        }
        public static Inventory menu = Bukkit.createInventory(null, 18, "Creative Inventory");
        // The first parameter, is the inventory owner. I make it null to let everyone use it.
        //The second parameter, is the slots in a inventory. Must be a multiple of 9. Can be up to 54.
        //The third parameter, is the inventory name. This will accept chat colors
        static {
                menu.setItem(0, new ItemStack(Material.PISTON_EXTENSION, 1));
                menu.setItem(1, new ItemStack(Material.FLOWER_POT_ITEM, 1));
                menu.setItem(2, new ItemStack(Material.BED_BLOCK, 1));
                menu.setItem(3, new ItemStack(Material.SKULL, 1));
                menu.setItem(4, new ItemStack(Material.SIGN_POST, 1));
                menu.setItem(5, new ItemStack(Material.BREWING_STAND, 1));
                menu.setItem(6, new ItemStack(Material.CAULDRON, 1));
                menu.setItem(7, new ItemStack(Material.IRON_DOOR_BLOCK, 1));
                menu.setItem(8, new ItemStack(Material.BURNING_FURNACE, 1));
                menu.setItem(9, new ItemStack(Material.REDSTONE_WIRE, 1));
                menu.setItem(10, new ItemStack(Material.REDSTONE_TORCH_OFF, 1));
                menu.setItem(11, new ItemStack(Material.REDSTONE_LAMP_ON, 1));
                menu.setItem(12, new ItemStack(Material.REDSTONE_COMPARATOR_ON, 1));
                menu.setItem(13, new ItemStack(Material.WATER, 1));
                menu.setItem(14, new ItemStack(Material.LAVA, 1));
                menu.setItem(15, new ItemStack(Material.CROPS, 1));
                menu.setItem(16, new ItemStack(Material.POTATO, 1));
                menu.setItem(17, new ItemStack(Material.CARROT, 1));
                menu.setItem(18, new ItemStack(Material.PUMPKIN_STEM, 1));
        }
        @EventHandler
       public void onInventoryClick(InventoryClickEvent event) { //clicks in menu
       Player player = (Player) event.getWhoClicked(); // The player that clicked the item
       ItemStack clicked = event.getCurrentItem(); // The item that was clicked
       Inventory inventory = event.getInventory(); // The inventory that was clicked in
       if (inventory.getName().equals(menu.getName())) {
       event.setCancelled(true);// Make it so the diamond is back in it's spot
       player.getInventory().addItem(clicked);
        }
        }
        }

    plugin.yml (open)

    Code:
    main: me.nelson2tm.creativeinventory.CreativeInventory
    name: CreativeInventory
    version: 1.0
    commands: 
      creativeinventory: 
        aliases: 
          - ci
          - technicalblocks
          - technicalitems
          - tb
          - ti
        description: "Open a menu with the technical blocks of Minecraft."
        permission: creativeinventory.open
    permissions:
      creativeinventory.open: 
        default: op

    Thanks for reading!
     
  2. Offline

    MCMastery

    nelson2tm May not affect anything, but I make my YML aliases differently:
    Code:
    main: me.nelson2tm.creativeinventory.CreativeInventory
    name: CreativeInventory
    version: 1.0
    commands:
      creativeinventory:
        aliases: [ci,technicalblocks,technicalitems,tb,ti]
        description: "Open a menu with the technical blocks of Minecraft."
        permission: creativeinventory.open
    permissions:
      creativeinventory.open:
        default: op
     
    nelson2tm likes this.
  3. Offline

    nelson2tm

  4. Offline

    SpaceManiac

    The section at the bottom of the error is most important:
    Code:
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 18
            at org.bukkit.craftbukkit.v1_7_R3.inventory.CraftInventoryCustom$MinecraftInventory.setItem(CraftInventoryCustom.java:103) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-65-gd550f2f-b3077jnks]
            at org.bukkit.craftbukkit.v1_7_R3.inventory.CraftInventory.setItem(CraftInventory.java:82) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-65-gd550f2f-b3077jnks]
            at me.nelson2tm.creativeinventory.CreativeInventory.<clinit>(CreativeInventory.java:60) ~[?:?]
            at java.lang.Class.forName0(Native Method) ~[?:1.7.0_55]
            at java.lang.Class.forName(Unknown Source) ~[?:1.7.0_55]
            at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:40) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-65-gd550f2f-b3077jnks]
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:127) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-65-gd550f2f-b3077jnks]
            ... 19 more
    
    You're trying to set slot number 18 on an 18-slot inventory, one past the end, which is the actual problem. The ExceptionInInitializerError part happens because you do this in a static block instead of your onEnable for some reason.
     
    nelson2tm likes this.
  5. Offline

    nelson2tm

    Thanks, next I need to better think in "computer" style. Counting starts at 0 and not at 1. forget that.
    [diamond] for helping SpaceManiac!
     
Thread Status:
Not open for further replies.

Share This Page