I have an issue with...

Discussion in 'Spigot Plugin Development' started by NaJated, May 21, 2015.

  1. ... I have an issue with my plugin variable always being null. I initialize it in the Main class' onEnable method that extends JavaPlugin.

    Error:
    Code (Text):
    java.lang.NullPointerException
        at me.TheGamesHawk2001.MineChill.Events.launchRandomSelectEvent(Events.java:52) ~[?:?]
        at me.TheGamesHawk2001.MineChill.Main.onEnable(Main.java:63) ~[?:?]
    Code:
    Events
    Code (Text):
            }.runTaskTimer(Main.getInstance().pl, 20 * startDelaySecs, mins);
    Main variable.

    Code (Text):
        Plugin pl = null;
        public static Main instance;

    onEnable method {
            pl = this;
            instance = this;

    }

        public void onDisable() {
            pl = null; //to prevent memory leaks
            instance = null; //to stop memory leaks again
            saveConfig();
            Bukkit.getScheduler().cancelAllTasks();

        }
     
  2. You don't need pl, since the Main class is already an instance of JavaPlugin (Plugin). Just use Main.getInstance();