NullPointerException

Discussion in 'Plugin Development' started by JRL1004, Sep 12, 2013.

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

    JRL1004

    I've recently started remaking some of my old plugin and I ran into a but when testing that outputs as a NPE. I have gone into the code and the exception is triggered when I tried to put an ELSE.
    I can't find a way to get the error to go away (even after reworking that entire portion of the file.)

    Here is the exception (I put it into a code box to save space):
    Code:
    2013-09-12 14:56:17 [INFO] JRL1004 issued server command: /pmode d
    2013-09-12 14:56:17 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'pmode' in plugin TurtlePopperV2 v2.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:191)
        at org.bukkit.craftbukkit.v1_6_R2.CraftServer.dispatchCommand(CraftServer.java:523)
        at net.minecraft.server.v1_6_R2.PlayerConnection.handleCommand(PlayerConnection.java:962)
        at net.minecraft.server.v1_6_R2.PlayerConnection.chat(PlayerConnection.java:880)
        at net.minecraft.server.v1_6_R2.PlayerConnection.a(PlayerConnection.java:837)
        at net.minecraft.server.v1_6_R2.Packet3Chat.handle(SourceFile:49)
        at net.minecraft.server.v1_6_R2.NetworkManager.b(NetworkManager.java:296)
        at net.minecraft.server.v1_6_R2.PlayerConnection.e(PlayerConnection.java:116)
        at net.minecraft.server.v1_6_R2.ServerConnection.b(SourceFile:37)
        at net.minecraft.server.v1_6_R2.DedicatedServerConnection.b(SourceFile:30)
        at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:590)
        at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:226)
        at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:486)
        at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:419)
        at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
    Caused by: java.lang.NullPointerException
        at turtleCraft.Popper.v2.Main.onCommand(Main.java:148)
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
        ... 15 more
    and here is the code I used in the section causing the exception:
    Code:java
    1. @Override
    2. public boolean onCommand(CommandSender sender, Command command,
    3. String label, String[] args) {
    4. if (label.equalsIgnoreCase("pMode")) {
    5. if (sender instanceof Player) {
    6. Player player = (Player) sender;
    7. String modeSwitch = getConfig().getString(
    8. "MagicSnowball-ModeSwitch");
    9. if (perms(player, modeSwitch)) {
    10. if (args.length != 1) {
    11. player.sendMessage(ChatColor.YELLOW + "Usage: /pMode <1-5>");
    12. }else{
    13. mS.setType(args[0]);
    14. }
    15. } else {
    16. player.sendMessage(ChatColor.RED
    17. + "You do not have to required permissions to do this!");
    18. }
    19. }
    20. }
    21. return false;
    22. }

    The @Override is at line 134 in Eclipse and the NPE is at line 148 "} else {"
     
  2. Offline

    metalhedd


    you're mistaken (looking at different source than you're actually running).

    a NPE Will not ever occur on that line.
     
  3. Offline

    JRL1004

    metalhedd If the NPE is not on that line, then where should I look? According to the stack trace it is caused by line 148 in Main (which is my else statement.)
     
  4. Offline

    metalhedd


    recompile the plugin and re-upload it. you're probably running an outdated jar where line 148 was something else.
     
  5. Offline

    JRL1004

    metalhedd Recompiled and I did not get an error (At least not on an else statement.) now I am getting an error when the plugin tries to call this method:
    Code:java
    1.  
    2.  
    3. public void setType(String type) {
    4. if (type.equalsIgnoreCase("One") || type.equalsIgnoreCase("1")) {
    5. mode.put(mPlayer, "One");
    6. }
    7. if (type.equalsIgnoreCase("Two") || type.equalsIgnoreCase("2")) {
    8. mode.put(mPlayer, "Two");
    9. }
    10. if (type.equalsIgnoreCase("Three") || type.equalsIgnoreCase("3")) {
    11. mode.put(mPlayer, "Three");
    12. }
    13. if (type.equalsIgnoreCase("Four") || type.equalsIgnoreCase("4")) {
    14. mode.put(mPlayer, "Four");
    15. }
    16. if (type.equalsIgnoreCase("Five") || type.equalsIgnoreCase("5")) {
    17. mode.put(mPlayer, "Five");
    18. } else {
    19. mode.put(mPlayer, pmode);
    20. mPlayer.sendMessage(ChatColor.RED
    21. + "Denied! You may not use the mode " + ChatColor.YELLOW
    22. + type + ChatColor.RED + " because it is not a valid mode!");
    23. mPlayer.sendMessage(ChatColor.RED
    24. + "You have been changed to mode " + ChatColor.YELLOW
    25. + pmode + ChatColor.RED
    26. + " do to your previous failed mode change");
    27. }
    28. }

    mode is a HashMap I made (set to <Player, String>)
     
  6. Offline

    metalhedd

    paste the full error message
     
  7. Offline

    JRL1004

    metalhedd Here you go:
    Code:
    2013-09-12 15:39:05 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'pmode' in plugin TurtlePopperV2 v2.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:191)
        at org.bukkit.craftbukkit.v1_6_R2.CraftServer.dispatchCommand(CraftServer.java:523)
        at net.minecraft.server.v1_6_R2.PlayerConnection.handleCommand(PlayerConnection.java:962)
        at net.minecraft.server.v1_6_R2.PlayerConnection.chat(PlayerConnection.java:880)
        at net.minecraft.server.v1_6_R2.PlayerConnection.a(PlayerConnection.java:837)
        at net.minecraft.server.v1_6_R2.Packet3Chat.handle(SourceFile:49)
        at net.minecraft.server.v1_6_R2.NetworkManager.b(NetworkManager.java:296)
        at net.minecraft.server.v1_6_R2.PlayerConnection.e(PlayerConnection.java:116)
        at net.minecraft.server.v1_6_R2.ServerConnection.b(SourceFile:37)
        at net.minecraft.server.v1_6_R2.DedicatedServerConnection.b(SourceFile:30)
        at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:590)
        at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:226)
        at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:486)
        at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:419)
        at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
    Caused by: java.lang.NullPointerException
        at turtleCraft.Popper.v2.Main.onCommand(Main.java:147)
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
        ... 15 more
    I just moved the code. For some reason it could not send the arguments from the player between files. It works now but the code is a bit more messy. Thanks for the help.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
Thread Status:
Not open for further replies.

Share This Page