Error with command!

Discussion in 'Plugin Development' started by edocsyl, Jan 29, 2012.

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

    edocsyl

    I don't know what's wrong..

    Code:
    2012-01-29 23:50:41 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'n' in plugin ServerNews v1.3
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:42)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:168)
        at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:386)
        at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.java:777)
        at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:737)
        at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:725)
        at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:33)
        at net.minecraft.server.NetworkManager.b(NetworkManager.java:226)
        at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:100)
        at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:78)
        at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:536)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:434)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:465)
    Caused by: java.lang.NullPointerException
        at me.edocsyl.ServerNews.ServerNews.onCommand(ServerNews.java:249)
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40)
        ... 12 more
    
    I have the same code onPlayer join, there it works..

    Source: https://github.com/Edocsyl/ServerNews/blob/master/src/me/edocsyl/ServerNews/ServerNews.java#L250

    Nobody who can say me, why i become this error?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 23, 2016
  2. Offline

    Slayer9x9

    Can you post your plugin.yml file?
     
  3. two things that might be the problem:
    first: it will give you a nullpointerexception every time you use the console, because p will still be null when it's not an instance of the player.
    second: did you define news and n in the plugin.yml?
     
  4. Offline

    edocsyl

  5. i would place the code INSIDE the if.
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args{
    {
        if (sender instanceof Player)
        {
            Player p = (Player)sender;
            // rest of the code here 
        }
    }
     
  6. Offline

    edocsyl

    Still errors -.-
     
  7. still the same or still some others?
     
  8. Can you post current code?


    In plugin.yml you dont need a separate command for aliases.
    You can do this
    Code:
    commands:
        servernews:
            description: Main Command with args.
            aliases: [sn]
            usage: |
                /sn <values> -- Main Command with args.
        news:
            description: Main Command with args.
            aliases: [n]
            usage: |
                /news <values> -- Main Command with args.
     
  9. Offline

    edocsyl

    Yurij Here it is: https://github.com/Edocsyl/ServerNews
    kumpelblase2
    Code:
    2012-01-31 17:14:54 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'news' in plugin ServerNews v1.3
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:42)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:168)
        at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:386)
        at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.java:777)
        at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:737)
        at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:725)
        at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:33)
        at net.minecraft.server.NetworkManager.b(NetworkManager.java:226)
        at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:100)
        at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:78)
        at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:536)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:434)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:465)
    Caused by: java.lang.NullPointerException
        at me.edocsyl.ServerNews.ServerNews.onCommand(ServerNews.java:258)
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40)
        ... 12 more
    
    The same
     
  10. When do the errors occur?
     
  11. Offline

    Jozeth

    Code:
          public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
              if (!(sender instanceof Player)) {
                  sender.sendMessage("This command can be only used in-game!");
                  return true;
    }
    
     
  12. is the line 258 on github the same as your line 258, but i have no idea why cmd.getName().equalsIgnoreCase("news") could throw a nullpointerexception if you declared it in the plugin.yml like Yurij did....
     
  13. the change I suggested of the plugin.yml shouldn't have solved anything.
    If the commands only should be used ingame and not in the console you should check Jozeth's answer above.
     
  14. Offline

    edocsyl

    I changed this from Jozeth but there is still the same eroor.. Is ths

    if (cmd.getName().equalsIgnoreCase("news")) {
    }

    Maby this (red) is the problem.. i change to sender, it dont print out the content but the Commentar in the *plugin.yml* file...
     
  15. Offline

    Lolmewn

    You could also use, instead of cmd.getName(), commandLabel. I always do :)
     
  16. Offline

    edocsyl

    The special thing is..
    Code:
    /sn
    /sn toggle
    
    this works

    If i make
    Code:
    /sn n
    /sn news
    
    this don't works.. maby the content is incorrect, but i use the same content in the player join listener class and it works..
     
  17. stacktrace please
     
  18. Offline

    edocsyl

    @Yurij
    stacktrace please ?
     
  19. the error message in your first post is a stack trace
     
  20. Offline

    edocsyl

    A other thing..
    If i make it so:

    Code:
            if (cmd.getName().equalsIgnoreCase("news")) {
                    p.sendMessage(this.plugin.strPhpHeader.replaceAll("(?i)&([a-f0-9])", "\u00A7$1"));
     
                return true;
                }
    
    i got an error
    If i make it so:
    Code:
            if (cmd.getName().equalsIgnoreCase("news")) {
                    p.sendMessage(strPhpHeader.replaceAll("(?i)&([a-f0-9])", "\u00A7$1"));
     
                return true;
                }
    
    i dont get the error
     
  21. post error messages please
     
  22. Offline

    edocsyl

    This was the problem :
    Code:
    this.plugin.
    
    Does anyone know why this makes an error?
    Maybe would be very helpfully for other programmer too.

    Yurij without "this.plugin" i don't get any errors!
     
  23. because you didn't set it to a value.
     
  24. Offline

    edocsyl

  25. in your case, since you only use things in you main class, you don't need it.
    but come on, if you don't know how you set a value LEARN SOME JAVA.
     
Thread Status:
Not open for further replies.

Share This Page