ERROR LOG Code: 12:22:52 AM [SEVERE] null org.bukkit.command.CommandException: Unhandled exception executing command 'koth' in plugin King of The Hill v1.0 at org.bukkit.command.PluginCommand.execute(PluginCommand.java:42) at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:166) at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:484) at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.java:811) at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:771) at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:754) at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:34) at net.minecraft.server.NetworkManager.b(NetworkManager.java:246) at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:102) at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:82) at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:559) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:451) at net.minecraft.server.ThreadServerApplication.run(SourceFile:492) Caused by: java.lang.NullPointerException at me.MnMaxon.KoTH.Msg.onCmdTime(Msg.java:15) at me.MnMaxon.KoTH.Main.onCommand(Main.java:163) at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40) I know that this means that something on line 15 is null. CLASS MSG class Msg: Code: package me.MnMaxon.KoTH; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; public class CopyOfMsg { public static Main plugin; public static int playerTime; public static boolean onCmdTime(CommandSender sender, Command cmd, String commandLabel, String[] args) { Player player = (Player) sender; player.sendMessage(Main.GameInProgressName + "." + player.getDisplayName()); } } Line 15: Code: player.sendMessage(Main.GameInProgressName + "." + player.getDisplayName()); Config File Code: # default config.yml '1': MnMaxon: 0 TpLocation: X: 264 Y: 68 Z: -86 Yaw: 2.9999998 Winint1: X: 259.0 Y: 75.0 Z: -76.0 Yaw: {} Winint2: X: 255.0 Y: 74.0 Z: -80.0 Yaw: {} My userName is MnMaxon I think that: Code: Main.GameInProgressName + "." + player.getDisplayName(); should equal 0, not null ---------------------------------------------------------------- I'm new to java and making plugins, and I think this seems like an easy fix and I would really appreciate it if someone can help.
Thanks, but that's not my main class, my main class uses that class, would you know of another way to fix the error?
Your Msg class has no constructor, so you don't have the running instance of your plugin. plugin = null;
You've created the variable, but it's not been set to anything. A constructor is the method you call to create a new instance of a class. If you don't have a constructor, it assumes a no-arg constructor. But in order to obtain an instance of your main class you need to pass it in. On line 11, add this Code: public Msg(Main instance){ this.plugin = instance; } and whenever you make instances of this class, pass in the instance of your main class Code: Msg msg = new Msg(this); (assuming you're in your main class)
I don't think I did this wrong because I still get the same error, could you tell me what I did wrong? And thanks for the help so far. Main Class (named Main): Code: package me.MnMaxon.KoTH; import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.logging.Logger; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.command.*; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; public class Main extends JavaPlugin { public final Logger logger = Logger.getLogger("Minecraft"); public final MyPlayerListener pl = new MyPlayerListener(); public static Main plugin; @Override public void onEnable() { reloadConfig(); PluginManager pm = getServer().getPluginManager(); pm.registerEvents(this.pl, this); } public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { final Player player = (Player) sender; if (commandLabel.equalsIgnoreCase("KoTH")) { } else if (args[0].equalsIgnoreCase("Time")) { Msg msg = new Msg(plugin); msg.onCmdTime(sender, cmd, commandLabel, args); } return false; } } Msg Class: Code: package me.MnMaxon.KoTH; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; public class Msg { public static Main plugin; public static int playerTime; public Msg(Main instance) { Msg.plugin = instance; } public boolean onCmdTime(CommandSender sender, Command cmd, String commandLabel, String[] args) { Player player = (Player) sender; player.sendMessage(Main.GameInProgressName + "." + player.getDisplayName()); playerTime = plugin.getConfig().getInt( Main.GameInProgressName + "." + player.getDisplayName()); return false; } }
lol. Now you have the exact same issue in your main class. Don't use a variable to represent your main class. Delete the field 'plugin' in your main class and when you need to use its instance (like when your using the constructor for your Msg class) just use 'this'.