Null Pointer Exception

Discussion in 'Plugin Development' started by zakarls, Jun 1, 2014.

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

    zakarls

    Whenever I run my plugin on my server its fine until I perform the command. It gives me a null pointer exception.
    Code (Main Class):
    Code:java
    1. package me.zakarls.ranks;
    2.  
    3. import java.util.List;
    4. import java.util.logging.Logger;
    5.  
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.plugin.PluginDescriptionFile;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class Ranks extends JavaPlugin {
    14. public final Logger logger = Logger.getLogger("Minecraft");
    15. public static Ranks plugin;
    16.  
    17. @Override
    18. public void onDisable() {
    19. PluginDescriptionFile pdfFile = this.getDescription();
    20. this.logger.info(pdfFile.getName() + " Has Been Disabled!");
    21. }
    22.  
    23. @Override
    24. public void onEnable() {
    25. PluginDescriptionFile pdfFile = this.getDescription();
    26. this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion()
    27. + " Has Been Enabled!");
    28. getConfig().options().copyDefaults(true);
    29. saveConfig();
    30. }
    31.  
    32. public boolean onCommand(CommandSender sender, Command cmd,
    33. String commandLabel, String[] args) {
    34. Player player = (Player) sender;
    35. if (commandLabel.equalsIgnoreCase("ranks")) {
    36. if (player.hasPermission("ranks.use") || player.isOp()) {
    37. List<String> rank = plugin.getConfig().getStringList("Ranks");
    38. for (String ranks : rank) {
    39. player.sendMessage(ranks);
    40. }
    41. }
    42. else{
    43. player.sendMessage(ChatColor.RED + "You Do Not Have Permission For This Command");
    44. }
    45. }
    46. return false;
    47. }
    48. }

    plugin.yml:
    Code:
    name: Ranks
    main: me.zakarls.ranks.Ranks
    version: 1.2
    description: >
                Rank List Plugin
    commands:
      ranks:
        description: Lists Ranks
    permissions:
      ranks.use:
        description: User-friendly description
        default: op
    config.yml:
    Code:
    ########################################################################################
    #                        Ranks By Zakarls                                            #
    #This is exactly what will display in the message so if you want to add $, do it here. #
    #                                                                                      #
    ########################################################################################
    Ranks:
    - A
    - B
    - C
    Error:
    Code:
    org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    01.06 14:40:03 [Server] INFO at me.zakarls.ranks.Ranks.onCommand(Ranks.java:37) ~[?:?]
    01.06 14:40:03 [Server] INFO Caused by: java.lang.NullPointerException
    01.06 14:40:03 [Server] INFO at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    01.06 14:40:03 [Server] INFO at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    01.06 14:40:03 [Server] INFO at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    01.06 14:40:03 [Server] INFO at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    01.06 14:40:03 [Server] INFO at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    01.06 14:40:03 [Server] INFO at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    01.06 14:40:03 [Server] INFO at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146) [craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    01.06 14:40:03 [Server] INFO at net.minecraft.server.v1_7_R1.PacketPlayInChat.handle(PacketPlayInChat.java:47) [craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    01.06 14:40:03 [Server] INFO at net.minecraft.server.v1_7_R1.PacketPlayInChat.a(PacketPlayInChat.java:28) [craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    01.06 14:40:03 [Server] INFO at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:814) [craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    01.06 14:40:03 [Server] INFO at net.minecraft.server.v1_7_R1.PlayerConnection.handleCommand(PlayerConnection.java:952) [craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    01.06 14:40:03 [Server] INFO at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCommand(CraftServer.java:683) ~[craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    01.06 14:40:03 [Server] INFO at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:175) ~[craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    01.06 14:40:03 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    01.06 14:40:03 [Server] INFO org.bukkit.command.CommandException: Unhandled exception executing command 'ranks' in plugin Ranks v1.2
    01.06 14:40:03 [Server] ERROR null
    01.06 14:40:03 [Server] INFO zakarls: Reload complete.
    01.06 14:40:03 [Server] INFO Server permissions file permissions.yml is empty, ignoring it
    01.06 14:40:03 [Server] INFO Ranks Version 1.2 Has Been Enabled!
    01.06 14:40:03 [Server] INFO Enabling Ranks v1.2
    01.06 14:40:03 [Server] INFO Loading Ranks v1.2
    01.06 14:40:03 [Server] INFO Ranks Has Been Disabled!
    01.06 14:40:03 [Server] INFO Disabling Ranks v1.2
    01.06 14:37:35 [Server] INFO World saved.
    01.06 14:37:35 [Server] INFO CONSOLE: Forcing save..
    01.06 14:37:35 [Server] INFO CONSOLE: Enabled level saving..
    01.06 14:37:35 [Multicraft] Auto-saving world...
    01.06 14:35:56 [Server] INFO ... 13 more
    01.06 14:35:56 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    01.06 14:35:56 [Server] INFO at me.zakarls.ranks.Ranks.onCommand(Ranks.java:38) ~[?:?]
    01.06 14:35:56 [Server] INFO Caused by: java.lang.NullPointerException
    01.06 14:35:56 [Server] INFO at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    01.06 14:35:56 [Server] INFO at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    01.06 14:35:56 [Server] INFO at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    01.06 14:35:56 [Server] INFO at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    01.06 14:35:56 [Server] INFO at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    01.06 14:35:56 [Server] INFO at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    01.06 14:35:56 [Server] INFO at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146) [craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    01.06 14:35:56 [Server] INFO at net.minecraft.server.v1_7_R1.PacketPlayInChat.handle(PacketPlayInChat.java:47) [craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    01.06 14:35:56 [Server] INFO at net.minecraft.server.v1_7_R1.PacketPlayInChat.a(PacketPlayInChat.java:28) [craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    01.06 14:35:56 [Server] INFO at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:814) [craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    01.06 14:35:56 [Server] INFO at net.minecraft.server.v1_7_R1.PlayerConnection.handleCommand(PlayerConnection.java:952) [craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    01.06 14:35:56 [Server] INFO at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCommand(CraftServer.java:683) ~[craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    01.06 14:35:56 [Server] INFO at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:175) ~[craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    01.06 14:35:56 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit_beta.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    01.06 14:35:56 [Server] INFO org.bukkit.command.CommandException: Unhandled exception executing command 'ranks' in plugin Ranks v1.2
    01.06 14:35:56 [Server] ERROR null
     
  2. Offline

    Zupsub

    Have read the stacktrace? Did you check the line the error occurs?
     
  3. Offline

    zakarls

    Zupsub
    It occurs on this line:
    Code:java
    1. List<String> rank = plugin.getConfig().getStringList("Ranks");
     
  4. Offline

    NathanWolf

    It doesn't look like you ever assign anything to that always-problematic static Plugin instance. You also don't need it- remove "plugin" and use "this" instead, at least for now.
     
  5. Offline

    zakarls

    NathanWolf
    I used this and the same thing happened

    NathanWolf
    I also removed the static plugin instance

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 1, 2016
  6. Offline

    NathanWolf

    Errrr I guess I don't know then! Check to make sure getConfig isn't returning null for some reason?
     
Thread Status:
Not open for further replies.

Share This Page