Solved NullPointerException on firing custom event

Discussion in 'Plugin Development' started by HeroWorkbrine, Jul 5, 2014.

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

    HeroWorkbrine

    Hi everyone!

    When I fire my own custom event:
    Code:java
    1. public void playerJoin(Player player) {
    2. MinigameJoinEvent joinEvent = new MinigameJoinEvent(this, mini, player);
    3. Bukkit.getServer().getPluginManager().callEvent(joinEvent); //Error line
    4.  
    5. if (!joinEvent.isCancelled()) {
    6. //Stuff
    7. }
    8. }

    Code:java
    1. package me.heroworkbrine.minigames.event;
    2.  
    3. import me.heroworkbrine.minigames.ActiveMinigame;
    4. import me.heroworkbrine.minigames.Minigame;
    5.  
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.Cancellable;
    8. import org.bukkit.event.HandlerList;
    9.  
    10. public class MinigameJoinEvent extends MinigamePlayerEvent implements Cancellable {
    11.  
    12. private static final HandlerList handlers = new HandlerList();
    13.  
    14. protected boolean cancelled = false;
    15.  
    16. public MinigameJoinEvent(ActiveMinigame mini, Minigame minigame, Player player) {
    17. super(mini, minigame, player);
    18. }
    19.  
    20. @Override
    21. public boolean isCancelled() {
    22. return cancelled;
    23. }
    24.  
    25. @Override
    26. public void setCancelled(boolean arg0) {
    27. cancelled = arg0;
    28. }
    29.  
    30. @Override
    31. public HandlerList getHandlers() {
    32. return null;
    33. }
    34.  
    35. public static HandlerList getHandlerList() {
    36. return handlers;
    37. }
    38.  
    39. }
    40.  


    I get this error:
     
  2. Offline

    Rocoty

    And we are supposed to know which line it is complaining about? Please tell us which lines are mentioned in the stack trace. Also such a short snippet is rarely enough for a nullpointerexception. Please post the whole class.
     
  3. Offline

    HeroWorkbrine

    I added the JoinMinigameEvent class
     
  4. Offline

    SpaceManiac

    You have:
    Code:
    @Override
    public HandlerList getHandlers() {
    return null;
    }
    
    This function needs to be returning the 'handlers' variable, just like the other method.
     
  5. Offline

    HeroWorkbrine

    How could I be so blind! Thanks, it works now!
     
Thread Status:
Not open for further replies.

Share This Page