Unhandled exception executing Error

Discussion in 'Plugin Development' started by rlagur55, Oct 23, 2013.

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

    rlagur55

    I made HeroesInventory Plugin

    but have some error

    Source Code:
    package inventoryplugin;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Server;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.inventory.InventoryType;
    import org.bukkit.event.player.PlayerChatEvent;
    import org.bukkit.event.player.PlayerCommandPreprocessEvent;
    import org.bukkit.event.player.PlayerEvent;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;
    import com.herocraftonline.heroes.Heroes;
    import com.herocraftonline.heroes.characters.CharacterManager;
    import com.herocraftonline.heroes.characters.Hero;
    import com.herocraftonline.heroes.characters.classes.HeroClass;
    import com.herocraftonline.heroes.characters.classes.HeroClassManager;
    public final class HeroesInventory extends JavaPlugin {

    private CharacterManager heroManager;
    private HeroClassManager classManager;
    private void setupHeroManager() {

    Plugin plugin = getServer().getPluginManager().getPlugin("Heroes");

    heroManager = ((Heroes) plugin).getCharacterManager();
    }

    private void setupClassManager() {

    Plugin plugin = getServer().getPluginManager().getPlugin("Heroes");

    classManager = ((Heroes) plugin).getClassManager();
    }
    public HeroClassManager getClassManager() {
    return classManager;
    }
    public CharacterManager getHeroManager() {
    return heroManager;
    }

    public void onEnable(){
    setupHeroManager();
    setupClassManager();
    getLogger().info("Disabled!");
    }
    public void onDisable(){
    getLogger().info("Enabled!");
    }

    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    Player player = (Player) sender;
    if(cmd.getName().equalsIgnoreCase("lego")){
    player.sendMessage(ChatColor.AQUA + "Hello World!");
    Hero hero = getHeroManager().getHero(player);
    Inventory inv = Bukkit.getServer().createInventory(null, 27, hero.getName());
    player.openInventory(inv);
    }

    return false;


    }
    }

    Console Log:
    2013-10-23 22:34:44 [INFO] kim issued server command: /lego
    2013-10-23 22:34:44 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'lego' in plugin Plugin v1.5.4-SNAPSHOT
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:192)
    at org.bukkit.craftbukkit.v1_6_R3.CraftServer.dispatchCommand(CraftServer.java:548)
    at net.minecraft.network.NetServerHandler.func_72566_d(NetServerHandler.java:1362)
    at net.minecraft.network.NetServerHandler.chat(NetServerHandler.java:1228)
    at net.minecraft.network.NetServerHandler.func_72481_a(NetServerHandler.java:1171)
    at net.minecraft.network.packet.Packet3Chat.func_73279_a(Packet3Chat.java:68)
    at net.minecraft.network.TcpConnection.func_74428_b(TcpConnection.java:469)
    at net.minecraft.network.NetServerHandler.func_72570_d(NetServerHandler.java:232)
    at net.minecraft.network.NetworkListenThread.func_71747_b(NetworkListenThread.java:54)
    at net.minecraft.server.dedicated.DedicatedServerListenThread.func_71747_b(DedicatedServerListenThread.java:34)
    at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:898)
    at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:328)
    at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:765)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:647)
    at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16)
    Caused by: java.lang.NullPointerException
    at inventoryplugin.HeroesInventory.onCommand(HeroesInventory.java:61)
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    ... 15 more
     
  2. Offline

    Jalau

    What is the line 61 in your code? To lazy to count.... Also please use the code button to format your code and error
     
  3. Offline

    whitehooder

    The error lies here
    Code:java
    1. Inventory inv = Bukkit.getServer().createInventory(null, 27, hero.getName());
    2. player.openInventory(inv);

    hero.getName() is the error.
     
  4. Offline

    rlagur55

    how to fix?
     
  5. Offline

    MrSparkzz

    rlagur55
    change
    Code:java
    1.  
    2. Inventory inv = Bukkit.getServer().createInventory(null, 27, hero.getName());
    3. player.openInventory(inv);
    4.  

    to
    Code:java
    1.  
    2. if (hero != null) {
    3. Inventory inv = Bukkit.getServer().createInventory(null, 27, hero.getName());
    4. player.openInventory(inv);
    5. }
    6.  
     
  6. Offline

    rlagur55

    I use this source

    but nothing happened
     

    Attached Files:

  7. Offline

    MrSparkzz

    There must've been a new stacktrace (Error). Copy the new stacktrace (if there is one) and post it.
     
  8. Offline

    whitehooder

    Nothing is happening because hero is null, therefore skipping the code.
    Without showing us your other class we cannot find the errors.
     
  9. Offline

    rlagur55

    Sorry I make a tongueslip

    MrSparkzz said:
    @rlagur55
    change
    Code:java
    1. Inventory inv = Bukkit.getServer().createInventory(null, 27, hero.getName());
    2. player.openInventory(inv);

    to
    Code:java
    1. if (hero != null) {
    2. Inventory inv = Bukkit.getServer().createInventory(null, 27, hero.getName());
    3. player.openInventory(inv);
    4. }
    I use this source

    but same error
     
  10. Offline

    whitehooder

    You mean you get nearly the same error? The error should lie on line 62 if it is the same, but it can't be. Please post the new stack trace or tell me the error lies on line 62 :)
     
  11. Offline

    xTrollxDudex

    Let see getHero() in the HeroesManager class
     
  12. Offline

    rlagur55

    getHero

    public Hero getHero(org.bukkit.entity.Player player)
    Gets a hero Object from the hero mapping, if the hero does not exist then it loads in the Hero object for the player
    Parameters:
    player-
    Returns:
     
  13. Offline

    xTrollxDudex

Thread Status:
Not open for further replies.

Share This Page