java.lang.NullPointerException with plugin

Discussion in 'Plugin Development' started by Fingolfin, Apr 17, 2021.

  1. Offline

    Fingolfin

    So I tried to code my own plugins and it worked for a while but after coming back to it after a long pause my commands do not work anymore.. it only throws a `java.lang.NullPointerException`
    Here is my code so far:
    ```
    public class Main extends JavaPlugin {
    public void onEnable() {
    saveDefaultConfig();
    new HelloCommand(this);
    }}
    ```
    and my HelloCommand Plugin:
    public class HelloCommand implements CommandExecutor {
    private Main plugin1;
    public HelloCommand(Main plugin) {
    this.plugin1 = plugin;
    plugin.getCommand("hello").setExecutor(this);
    }

    @Overridepublic boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player)) {
    sender.sendMessage("Only player should execute dad shyte");
    return true;
    }}
    }
    ```
    I really appreciate any help!

    the error message:
    ```
    java.lang.NullPointerException
    at me.fingolfin.helloworld.commands.HelloCommand.<init>(HelloCommand.java:15) ~[?:?]
    at me.fingolfin.helloworld.Main.onEnable(Main.java:16) ~[?:?]
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
    at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:357) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
    at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:317) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
    at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:414) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
    at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:378) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
    at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:333) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
    at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:263) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
    at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:525) [spigot-1.8.8.jar:git-Spigot-21fe707-e1ebe52]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_282]
    ```

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Apr 17, 2021
  2. Offline

    timtower Administrator Administrator Moderator

    @Fingolfin Did you register the command in the plugin.yml?
     

Share This Page