Unhandled exception executing command

Discussion in 'Plugin Development' started by dan14941, Apr 6, 2014.

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

    dan14941

    Im trying to make my code test if a person has a certain boolean on a config file but its not working?

    here is the bit from my mane code you need:
    Code:java
    1. YamlConfiguration playerInfo;
    2.  
    3. String pfile;
    4.  
    5. ...
    6. public void onEnable()
    7. {
    8. pfile = (getDataFolder().getAbsolutePath() + "/player-info.yml");
    9.  
    10. File playerInfoF = new File(getDataFolder().getAbsolutePath() + "/player-info.yml");
    11.  
    12. playerInfo = YamlConfiguration.loadConfiguration(playerInfoF);
    13.  
    14. savePlayerInfo();
    15.  
    16. logger.info("Companies plugin loaded!");
    17. }
    18.  
    19. public void savePlayerInfo()
    20. {
    21. try
    22. {
    23. playerInfo.save(pfile);
    24. }
    25. catch (Exception e)
    26. {
    27. e.printStackTrace();
    28. }
    29. }
    30.  
    31.  


    and my command file:
    Code:
    YamlConfiguration playerInfo;
       
        String pfile;
       
        public void savePlayerInfo()
        {
            try
            {
                playerInfo.save(pfile);
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
        }
       
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
        {
            String prefix = ChatColor.translateAlternateColorCodes('&', "&e[Companies] ");
            Player player = (Player)sender;
           
            if(args.length >= 1 && args.length < 2)
            {
                if(args[0].equalsIgnoreCase("help"))
                {
                    // creates help in chat
                    player.sendMessage(ChatColor.AQUA + "+== Companies ==+");
                    player.sendMessage(ChatColor.YELLOW + "/company list" + ChatColor.GOLD + " Shows companys");
                    player.sendMessage(ChatColor.YELLOW + "/company <company name>" + ChatColor.GOLD + " Gets information on a company.");
                    if(player.hasPermission("companies.create"))
                    {
                        player.sendMessage(ChatColor.YELLOW + "/company create <company name>" + ChatColor.GOLD + " Creates a company");
                    }
                    player.sendMessage(ChatColor.YELLOW + "/company leave" + ChatColor.GOLD + " Leave your company");
                }
                else if(args[0].equalsIgnoreCase("leave"))
                {
    57                if(playerInfo.getBoolean("Players." + player.getName() + ".in-town"))
                    {
                        playerInfo.set("Players." + player.getName() + ".in-town", false);
                        if(playerInfo.getBoolean("Players." + player.getName() + ".in-town", true))
                        {
                            playerInfo.set("Players." + player.getName() + ".in-town", false);
                            savePlayerInfo();
                        }
                        else
                        {
                            player.sendMessage(prefix + ChatColor.GOLD + "You are not in a company!");
                        }
                    }
                }
            }
            else
            {
                player.sendMessage(prefix + ChatColor.RED + "Incorrect Syntax do /company help for commands!");
            }   
            return true;
        }
     
    }
    
    and my error log:
    Code:
    [17:08:39] [Server thread/INFO]: dan14941 issued server command: /company leave
    [17:08:39] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'company' in plugin Companies v0.1
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:175) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCommand(CraftServer.java:683) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.PlayerConnection.handleCommand(PlayerConnection.java:952) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:814) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInChat.a(PacketPlayInChat.java:28) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInChat.handle(PacketPlayInChat.java:47) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    Caused by: java.lang.NullPointerException
        at me.dan14941.companies.CompanyCommand.onCommand(CompanyCommand.java:57) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
        ... 13 more
    [17:12:05] [Server thread/WARN]: Can't keep up! Did the system time change, or is the server overloaded? Running 6851ms behind, skipping 137 tick(s)
    
     
  2. Offline

    SnipsRevival

    What is on line 57 of your CompanyCommand class?

    Also, this is completely irrelevant, but why do you have this check:
    Code:
    if(args.length >= 1 && args.length < 2)
    Instead, you could just write
    Code:
    if(args.length == 1)
     
  3. Offline

    dan14941

    SnipsRevival it was on a video tutorial lol

    SnipsRevival and i put on a number on line 57 in the code but here it is again.
    Code:java
    1. f(playerInfo.getBoolean("Players." + player.getName() + ".in-town"))


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  4. Offline

    SnipsRevival

    You never initialized playerInfo as far as I can tell. Make sure your playerInfo variable is actually referencing a YamlConfiguration.
     
  5. Offline

    dan14941

  6. Offline

    SnipsRevival

    dan14941 You have the line
    Code:
    YamlConfiguration playerInfo;
    but you haven't ever specified what playerInfo actually references.
     
  7. Offline

    dan14941

    SnipsRevival
    Code:
    playerInfo = YamlConfiguration.loadConfiguration(playerInfoF);
    that but its in the main class.
     
Thread Status:
Not open for further replies.

Share This Page