ERROR: null, what's wrong?

Discussion in 'Plugin Development' started by JayHerlth, Feb 9, 2014.

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

    JayHerlth

    I feel like I post too frequently in this forum seeking for help ... anywho. Would also like to note that the first command "/spadd Rawr_Inc" worked correctly, I was online. When I try a random set of characters of a player not online or at all it gives me this Error: null. I'd just like for it to check and see if the player is in the hashmap and if they aren't, go ahead and add them to it.
    Code:
    [21:49:37 INFO]: Rawr_Inc issued server command: /spadd Rawr_Inc
    [21:50:29 INFO]: Rawr_Inc issued server command: /spadd asdf
    [21:50:29 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'spad
    d' in plugin Splinters v0.1a
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[cra
    ftbukkit-1.7.2-R0.3-20140202.193358-30.jar:git-Bukkit-1.7.2-R0.2-36-g9f75167-b30
    05jnks]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:19
    9) ~[craftbukkit-1.7.2-R0.3-20140202.193358-30.jar:git-Bukkit-1.7.2-R0.2-36-g9f7
    5167-b3005jnks]
            at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCommand(CraftServe
    r.java:543) ~[craftbukkit-1.7.2-R0.3-20140202.193358-30.jar:git-Bukkit-1.7.2-R0.
    2-36-g9f75167-b3005jnks]
            at net.minecraft.server.v1_7_R1.PlayerConnection.handleCommand(PlayerCon
    nection.java:932) [craftbukkit-1.7.2-R0.3-20140202.193358-30.jar:git-Bukkit-1.7.
    2-R0.2-36-g9f75167-b3005jnks]
            at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java
    :814) [craftbukkit-1.7.2-R0.3-20140202.193358-30.jar:git-Bukkit-1.7.2-R0.2-36-g9
    f75167-b3005jnks]
            at net.minecraft.server.v1_7_R1.PacketPlayInChat.a(PacketPlayInChat.java
    :28) [craftbukkit-1.7.2-R0.3-20140202.193358-30.jar:git-Bukkit-1.7.2-R0.2-36-g9f
    75167-b3005jnks]
            at net.minecraft.server.v1_7_R1.PacketPlayInChat.handle(PacketPlayInChat
    .java:47) [craftbukkit-1.7.2-R0.3-20140202.193358-30.jar:git-Bukkit-1.7.2-R0.2-3
    6-g9f75167-b3005jnks]
            at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146
    ) [craftbukkit-1.7.2-R0.3-20140202.193358-30.jar:git-Bukkit-1.7.2-R0.2-36-g9f751
    67-b3005jnks]
            at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craf
    tbukkit-1.7.2-R0.3-20140202.193358-30.jar:git-Bukkit-1.7.2-R0.2-36-g9f75167-b300
    5jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:6
    55) [craftbukkit-1.7.2-R0.3-20140202.193358-30.jar:git-Bukkit-1.7.2-R0.2-36-g9f7
    5167-b3005jnks]
            at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:2
    50) [craftbukkit-1.7.2-R0.3-20140202.193358-30.jar:git-Bukkit-1.7.2-R0.2-36-g9f7
    5167-b3005jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:5
    45) [craftbukkit-1.7.2-R0.3-20140202.193358-30.jar:git-Bukkit-1.7.2-R0.2-36-g9f7
    5167-b3005jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java
    :457) [craftbukkit-1.7.2-R0.3-20140202.193358-30.jar:git-Bukkit-1.7.2-R0.2-36-g9
    f75167-b3005jnks]
            at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:6
    17) [craftbukkit-1.7.2-R0.3-20140202.193358-30.jar:git-Bukkit-1.7.2-R0.2-36-g9f7
    5167-b3005jnks]
    Caused by: java.lang.NullPointerException
            at me.jayherlth.splinters.Main.onCommand(Main.java:61) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[cra
    ftbukkit-1.7.2-R0.3-20140202.193358-30.jar:git-Bukkit-1.7.2-R0.2-36-g9f75167-b30
    05jnks]
    Here is my code, it's saying something about line 61 on my side of the code which would be
    Code:java
    1. sender.sendMessage(ChatColor.YELLOW + targetName + ", is already on the whitelist."); // Send confirmation message

    Code:
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String CommandLabel, String[] args) {
    2. if (sender.hasPermission("sp.*")) { // If the player has permission do the following...
    3. if (cmd.getName().equalsIgnoreCase("spadd")) { // If the player issued the /spadd command do this...
    4. if (args.length == 0) { // If no arguments have been entered...
    5. sender.sendMessage(ChatColor.YELLOW + "Please enter a valid player name.");
    6. return true;
    7. } else if (args != null) { // If the arguments aren't equal to nothing...
    8. String targetName = args[0];
    9. if (whitelist.get(targetName)){ // Check to see if the player is already in the whitelist...
    10. sender.sendMessage(ChatColor.YELLOW + targetName + ", is already on the whitelist."); // Send confirmation message
    11. return true;
    12. } else { // If the player isn't returning true in the whitelist then...
    13. whitelist.put(targetName, true); // Add the player name as "key" and set to true
    14. sender.sendMessage(ChatColor.YELLOW + targetName + ", has been added."); // Send confirmation message
    15. return true;
    16. }
    17. }
    18. }
    19.  
    20. }
    21. return false;
    22. }
     
  2. Offline

    Jake6177

    targetName is null, somehow.

    You should check the argument's length not if they're null.
     
  3. Offline

    AoH_Ruthless

    JayHerlth
    What's line 61? Also, you don't need to check if "args != null"... just use 'else' without any other specifications, because if the args.length isn't 0, it can't be null.
     
  4. Offline

    JayHerlth

    AoH_Ruthless & Jake6177
    I had found out that my error was that with a .get() method on a HashMap if it doesn't have a value in the hashmap it will return null and that is where my null value came into play so I worked my way around it in my if statement and modified the code a little bit.

    Code:java
    1. if (whitelist.get(targetName) != null | false) { // Check to see if the player is already in the whitelist...
     
  5. Offline

    AoH_Ruthless

  6. Offline

    JayHerlth

    I'm sorry, it was a late night. Forgot to mark as solved, thank you AoH_Ruthless
     
Thread Status:
Not open for further replies.

Share This Page