title: How to fix java.lang.NullPointerException: null in Bukkit plugin?
body: <p>Can't understand how to fix that error, it's unreal to me (can't find where's void in my code):</p>
  
  <pre><code>java.lang.NullPointerException: null
      at survival.MainClass.onEnable(MainClass.java:16) ~[?:?]
      at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[spigot.jar:git-Spigot-dcd1643-e60fc34]
      at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337) [spigot.jar:git-Spigot-dcd1643-e60fc34]
      at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:403) [spigot.jar:git-Spigot-dcd1643-e60fc34]
      at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugin(CraftServer.java:381) [spigot.jar:git-Spigot-dcd1643-e60fc34]
      at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugins(CraftServer.java:330) [spigot.jar:git-Spigot-dcd1643-e60fc34]
      at net.minecraft.server.v1_12_R1.MinecraftServer.t(MinecraftServer.java:422) [spigot.jar:git-Spigot-dcd1643-e60fc34]
      at net.minecraft.server.v1_12_R1.MinecraftServer.l(MinecraftServer.java:383) [spigot.jar:git-Spigot-dcd1643-e60fc34]
      at net.minecraft.server.v1_12_R1.MinecraftServer.a(MinecraftServer.java:338) [spigot.jar:git-Spigot-dcd1643-e60fc34]
      at net.minecraft.server.v1_12_R1.DedicatedServer.init(DedicatedServer.java:272) [spigot.jar:git-Spigot-dcd1643-e60fc34]
      at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:545) [spigot.jar:git-Spigot-dcd1643-e60fc34]
      at java.lang.Thread.run(Unknown Source) [?:1.8.0_161]
  </code></pre>
  
  <p>16 line is:</p>
  
  <pre><code>getCommand(commands.cmd3).setExecutor(commands);
  </code></pre>
  
  <p>Commands class:</p>
  
  <pre><code>public class Commands extends CommandExecute implements CommandExecutor, Listener {
  
  public String cmd1 = "fly";
  public String cmd2 = "feed";
  public String cmd3 = "heal";
  
  @Override
  public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
      if (sender instanceof Player) {
          if (cmd.getName().equalsIgnoreCase(cmd3)) {
              Player p = (Player) sender;
              if (p.getHealth() &lt; 20) {
                  p.setHealth(20);
                  p.sendMessage(ChatColor.GOLD + "Healed succesfuly!");
                  return true;
              } else {
                  p.sendMessage(ChatColor.RED + "You are already healed!");
                  return true;
              }
  
          }
          return false;
      } else {
          sender.sendMessage("Only for Players!");
          return true;
      }
  
    }
  
  }
  </code></pre>
  
  <p>MainClass:</p>
  
  <pre><code>public class MainClass extends JavaPlugin implements Listener{
  private Commands commands = new Commands();
  
  public void onEnable() {
      getServer().getPluginManager().registerEvents(new MainHandler(), this);
      getCommand(commands.cmd1).setExecutor(commands);
      getCommand(commands.cmd2).setExecutor(commands);
      getCommand(commands.cmd3).setExecutor(commands);
    }
  }
  </code></pre>
  
  <p>Have cmd1 and cmd2 before that and they're working fine, problem with only cmd3 command.</p>
  
  <p>in plugin.yml:</p>
  
  <pre><code>name: Survival
  main: survival.MainClass
  version: 1.1
  commands:
    fly:
      description: Toggle flight mode
      usage: /fly
    feed:
      description: Feeds player
      usage: /feed
    heal:
      description: Heals player
      usage: /heal
  </code></pre>
  
  <p>Tried all answers on stackoverflow, but nothing helped me </p>