java.lang.IllegalArgumentException: Plugin cannot be null

Discussion in 'Spigot Plugin Development' started by Aderm, Jun 3, 2016.

Thread Status:
Not open for further replies.
  1. Hey guys, so I coded a scoreboard, and I'm getting plugin cannot be null on line 73 - main class.

    Main class 73:
    Code (Java):

            }.runTaskTimer(getPlugin(), 0, 45);
     
    My other code
    Code (Java):

        private static Main plugin;
     
    Code (Java):

        public static Main getPlugin() {
            return plugin;
        }

        public static void setPlugin(Main plugin) {
            Main.plugin = plugin;
        }
     
    What I'm trying to do that's causing the error.

    Code (Java):

    new BukkitRunnable(){
                public void run() {
                    for (Player online : Bukkit.getOnlinePlayers()) {
                        SB.showBoard(online);
                    }
                }
            }.runTaskTimer(getPlugin(), 0, 45);
     
    Thanks
     
    #1 Aderm, Jun 3, 2016
    Last edited by a moderator: Aug 3, 2018
  2. You need to make a constructor in the classes that you want the instances for and in the main class pass the instance.
     
  3. You forgot to add setPlugin(this) on onEnable;
     
    • Agree Agree x 1
  4. Sw4p

    Supporter

    Not if the plugin instance is static which is what he is trying to do.
     
  5. That does not matter, if is static or not, he need to assign the plugin instance to the "plugin" variable.
     
  6. You can also change this
    private static Main plugin;

    to this
    private static Main plugin = JavaPlugin.getProvidingPlugin(Main.class);
     
  7. Sw4p

    Supporter

    Well im not sure why he needs a static reference if its going to be a private variable, couldn't he just use 'this' and do that same thing or am i missing something?
     
Thread Status:
Not open for further replies.