Solved Plugin cannot be null?

Discussion in 'Plugin Development' started by HeavyMine13, Jun 5, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    HeavyMine13

    Hey! So I am getting this error in a scheduler in the listener class! Stacktrace:

    Code:
    05.06 07:59:11 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3039jnks]
    05.06 07:59:11 [Server] INFO at me.HeavyMine13.snww.Snowma.onCommand(Snowma.java:97) ~[?:?]
    05.06 07:59:11 [Server] INFO at me.HeavyMine13.snww.logic.MatchAPI.pre(MatchAPI.java:54) ~[?:?]
    05.06 07:59:11 [Server] INFO at org.bukkit.craftbukkit.v1_7_R2.scheduler.CraftScheduler.scheduleSyncRepeatingTask(CraftScheduler.java:116) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3039jnks]
    05.06 07:59:11 [Server] INFO at org.bukkit.craftbukkit.v1_7_R2.scheduler.CraftScheduler.runTaskTimer(CraftScheduler.java:120) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3039jnks]
    05.06 07:59:11 [Server] INFO at org.bukkit.craftbukkit.v1_7_R2.scheduler.CraftScheduler.validate(CraftScheduler.java:391) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3039jnks]
    05.06 07:59:11 [Server] INFO at org.apache.commons.lang.Validate.notNull(Validate.java:203) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3039jnks]
    05.06 07:59:11 [Server] INFO Caused by: java.lang.IllegalArgumentException: Plugin cannot be null
    MatchAPI Line 54:
    Code:java
    1. taskID2 = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {


    I tried this but did not work:
    Code:java
    1. private static Snowma plugin;
    2.  
    3.  
    4. public MatchAPI(Snowma plugin){
    5. MatchAPI.plugin = plugin;
    6. }


    Help!
     
  2. Offline

    fireblast709

    Stop using static. That is most likely the cause of your issues. HeavyMine13
     
  3. Offline

    HeavyMine13

    Why? I need to use them in other classes ._.

    Of which class?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 30, 2016
  4. Offline

    Gater12

    HeavyMine13
    So pass instance through a constructor of those classes then?
     
  5. HeavyMine13 Preferably both the main and the Listener. And I agree, statics aren't the way forward.
     
  6. Offline

    HeavyMine13

    Hmm example?
     
  7. Offline

    fireblast709

  8. Offline

    Gater12

    HeavyMine13
    You just did one? The one with MatchAPI.
     
  9. Offline

    HeavyMine13

    Im using public static void thing(Parm m){
    //do stuff
    }

    Whats the difference?

    Ok if I change it(Which I can easily do), how can I use it?

    I have multiple statics I cant just turn each of them into MatchAPI(Parm)! Right?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 30, 2016
  10. As Gater12 pointed out... Here is an example of it being used

    It should look reasonably familiar. Change it to "this" rather than MatchAPI and remove the static from the variable, and there you have it!
     
  11. Offline

    HeavyMine13

    what static? there is no static in that constructor!
     
  12. Offline

    HeavyMine13

    Ok now after all is ok and removed many static, how can I use public void addPlayer(Player p){//blah} in the main class?
     
  13. Offline

    fireblast709

    HeavyMine13
    1. Create an instanceof the API in your main class
    2. access addPlayer(Player p) because it is most likely public
    3. ???
    4. profit
     
    HeavyMine13 likes this.
  14. Offline

    HeavyMine13

    Umm I need help with step 1 ._.
     
  15. Offline

    fireblast709

    HeavyMine13
    Code:java
    1. // From the main class, we use this.
    2. new MatchAPI(this)
     
  16. Offline

    HeavyMine13

    Ok addPlayer is public but how can I access it? Sorry, this is time #1 i dont use statics xD
     
  17. Offline

    L33m4n123

  18. Offline

    viper_monster

    HeavyMine13
    MatchAPI api = new MatchAPI(this);
    api.addPlayer(Player);

    woops haha, I have now realized I have tagged the wrong person, fireblast709, sorreh :p
     
    HeavyMine13 likes this.
  19. Offline

    HeavyMine13

    Last edited by a moderator: Jun 30, 2016
  20. Offline

    Bocktrow

    HeavyMine13 To nake it easy on yourself, you could always create a stastic instance of your class inside that class that will be initialized on startup. So basically somewhere in your class:
    Code:
    public static MainClass mainClass = null;


    In your onEnable()
    Code:
    mainClass = this;
     
  21. Offline

    HeavyMine13

    that didnt work last time with me :p
     
  22. Offline

    fireblast709

     
    HeavyMine13 likes this.
Thread Status:
Not open for further replies.

Share This Page