Having an NullPointer exception here cannot figure out why Code:java Player p = (Player) sender;API.setStats(p); try {StatTrack.kills.put(p.getUniqueId(), plugin.getConfig().getInt("kills." + p.getUniqueId()));StatTrack.deaths.put(p.getUniqueId(), plugin.getConfig().getInt("deaths." + p.getUniqueId()));StatTrack.points.put(p.getUniqueId(), plugin.getConfig().getInt("points." + p.getUniqueId()));} catch (NullPointerException ne) {System.out.println("Null Pointer Exception");}
StatTrack could be null, but without the stacktrace it's hard to tell. Could you post the stacktrace?
Code: [18:14:15 ERROR]: null org.bukkit.command.CommandException: Unhandled exception executing command 'stat s' in plugin StatTrack vv1.0 at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[cra ftbukkit-1.7.9.jar:git-Bukkit-1.7.2-R0.3-66-g43d8943-b3078jnks] at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:18 0) ~[craftbukkit-1.7.9.jar:git-Bukkit-1.7.2-R0.3-66-g43d8943-b3078jnks] at org.bukkit.craftbukkit.v1_7_R3.CraftServer.dispatchCommand(CraftServe r.java:703) ~[craftbukkit-1.7.9.jar:git-Bukkit-1.7.2-R0.3-66-g43d8943-b3078jnks] at net.minecraft.server.v1_7_R3.PlayerConnection.handleCommand(PlayerCon nection.java:955) [craftbukkit-1.7.9.jar:git-Bukkit-1.7.2-R0.3-66-g43d8943-b3078 jnks] at net.minecraft.server.v1_7_R3.PlayerConnection.a(PlayerConnection.java :817) [craftbukkit-1.7.9.jar:git-Bukkit-1.7.2-R0.3-66-g43d8943-b3078jnks] at net.minecraft.server.v1_7_R3.PacketPlayInChat.a(PacketPlayInChat.java :28) [craftbukkit-1.7.9.jar:git-Bukkit-1.7.2-R0.3-66-g43d8943-b3078jnks] at net.minecraft.server.v1_7_R3.PacketPlayInChat.handle(PacketPlayInChat .java:47) [craftbukkit-1.7.9.jar:git-Bukkit-1.7.2-R0.3-66-g43d8943-b3078jnks] at net.minecraft.server.v1_7_R3.NetworkManager.a(NetworkManager.java:157 ) [craftbukkit-1.7.9.jar:git-Bukkit-1.7.2-R0.3-66-g43d8943-b3078jnks] at net.minecraft.server.v1_7_R3.ServerConnection.c(SourceFile:134) [craf tbukkit-1.7.9.jar:git-Bukkit-1.7.2-R0.3-66-g43d8943-b3078jnks] at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:6 67) [craftbukkit-1.7.9.jar:git-Bukkit-1.7.2-R0.3-66-g43d8943-b3078jnks] at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:2 60) [craftbukkit-1.7.9.jar:git-Bukkit-1.7.2-R0.3-66-g43d8943-b3078jnks] at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:5 58) [craftbukkit-1.7.9.jar:git-Bukkit-1.7.2-R0.3-66-g43d8943-b3078jnks] at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java :469) [craftbukkit-1.7.9.jar:git-Bukkit-1.7.2-R0.3-66-g43d8943-b3078jnks] at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:6 28) [craftbukkit-1.7.9.jar:git-Bukkit-1.7.2-R0.3-66-g43d8943-b3078jnks] Caused by: java.lang.NullPointerException at me.duuckky.commands.ShowStats.onCommand(ShowStats.java:22) ~[?:?] at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[cra ftbukkit-1.7.9.jar:git-Bukkit-1.7.2-R0.3-66-g43d8943-b3078jnks] ... 13 more Code:java package me.duuckky.commands; import me.duuckky.API;import me.duuckky.StatTrack; import org.bukkit.command.Command;import org.bukkit.command.CommandExecutor;import org.bukkit.command.CommandSender;import org.bukkit.entity.Player; public class ShowStats implements CommandExecutor { public StatTrack plugin; @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { Player p = (Player) sender; API.setStats(p); StatTrack.kills.put(p.getUniqueId(), plugin.getConfig().getInt("kills." + p.getUniqueId())); StatTrack.deaths.put(p.getUniqueId(), plugin.getConfig().getInt("deaths." + p.getUniqueId())); StatTrack.points.put(p.getUniqueId(), plugin.getConfig().getInt("points." + p.getUniqueId())); if(sender instanceof Player) { if(args.length == 1) { API.showStats(p, args[0]); return true; } else if(args.length == 0) { API.showStats(p, p.getName()); return true; } } return false; }}
The error is at line 22, so probably StatTrack is null or the kills variable in StatTrack is null. Check it at line 21 and print out a message if it is null. Edit: pretty sure StatTrack is null, you never assign a value to it, you will need a constructor to do that.
I added a check Code:java package me.duuckky.commands; import me.duuckky.API;import me.duuckky.StatTrack; import org.bukkit.command.Command;import org.bukkit.command.CommandExecutor;import org.bukkit.command.CommandSender;import org.bukkit.entity.Player; public class ShowStats implements CommandExecutor { public StatTrack plugin; @Overridepublic boolean onCommand(CommandSender sender, Command cmd, String label,String[] args) { Player p = (Player) sender; API.setStats(p); if(StatTrack.kills == null ) {System.out.println("null");} StatTrack.kills.put(p.getUniqueId(), plugin.getConfig().getInt("kills." + p.getUniqueId()));StatTrack.deaths.put(p.getUniqueId(), plugin.getConfig().getInt("deaths." + p.getUniqueId()));StatTrack.points.put(p.getUniqueId(), plugin.getConfig().getInt("points." + p.getUniqueId())); if(sender instanceof Player) { if(args.length == 1) {API.showStats(p, args[0]);return true;} else if(args.length == 0) {API.showStats(p, p.getName());return true;}}return false;}} now i get the error Code: [18:37:42 ERROR]: null org.bukkit.command.CommandException: Unhandled exception executing command 'stat s' in plugin StatTrack vv1.0 at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[cra ftbukkit-1.7.9.jar:git-Bukkit-1.7.2-R0.3-66-g43d8943-b3078jnks] at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:18 0) ~[craftbukkit-1.7.9.jar:git-Bukkit-1.7.2-R0.3-66-g43d8943-b3078jnks] at org.bukkit.craftbukkit.v1_7_R3.CraftServer.dispatchCommand(CraftServe r.java:703) ~[craftbukkit-1.7.9.jar:git-Bukkit-1.7.2-R0.3-66-g43d8943-b3078jnks] at net.minecraft.server.v1_7_R3.PlayerConnection.handleCommand(PlayerCon nection.java:955) [craftbukkit-1.7.9.jar:git-Bukkit-1.7.2-R0.3-66-g43d8943-b3078 jnks] at net.minecraft.server.v1_7_R3.PlayerConnection.a(PlayerConnection.java :817) [craftbukkit-1.7.9.jar:git-Bukkit-1.7.2-R0.3-66-g43d8943-b3078jnks] at net.minecraft.server.v1_7_R3.PacketPlayInChat.a(PacketPlayInChat.java :28) [craftbukkit-1.7.9.jar:git-Bukkit-1.7.2-R0.3-66-g43d8943-b3078jnks] at net.minecraft.server.v1_7_R3.PacketPlayInChat.handle(PacketPlayInChat .java:47) [craftbukkit-1.7.9.jar:git-Bukkit-1.7.2-R0.3-66-g43d8943-b3078jnks] at net.minecraft.server.v1_7_R3.NetworkManager.a(NetworkManager.java:157 ) [craftbukkit-1.7.9.jar:git-Bukkit-1.7.2-R0.3-66-g43d8943-b3078jnks] at net.minecraft.server.v1_7_R3.ServerConnection.c(SourceFile:134) [craf tbukkit-1.7.9.jar:git-Bukkit-1.7.2-R0.3-66-g43d8943-b3078jnks] at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:6 67) [craftbukkit-1.7.9.jar:git-Bukkit-1.7.2-R0.3-66-g43d8943-b3078jnks] at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:2 60) [craftbukkit-1.7.9.jar:git-Bukkit-1.7.2-R0.3-66-g43d8943-b3078jnks] at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:5 58) [craftbukkit-1.7.9.jar:git-Bukkit-1.7.2-R0.3-66-g43d8943-b3078jnks] at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java :469) [craftbukkit-1.7.9.jar:git-Bukkit-1.7.2-R0.3-66-g43d8943-b3078jnks] at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:6 28) [craftbukkit-1.7.9.jar:git-Bukkit-1.7.2-R0.3-66-g43d8943-b3078jnks] Caused by: java.lang.NullPointerException at me.duuckky.commands.ShowStats.onCommand(ShowStats.java:21) ~[?:?] at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[cra ftbukkit-1.7.9.jar:git-Bukkit-1.7.2-R0.3-66-g43d8943-b3078jnks] ... 13 more Thanks! Got it c: EDIT by Moderator: merged posts, please use the edit button instead of double posting.