NullPointerException problem

Discussion in 'Spigot Plugin Development' started by WildPvPer, Jun 29, 2016.

  1. I'm coding a voting related plugin and i've got everything to work except the registering it keeps giving me a NullPointerException, i've read the Stack Traces and found the lines of code that it doesn't like but i can't figure out how to fix it

    I'll post the 2 classes that have the problem and point out the line of code

    Code (Text):
     if ((args.length == 1) && (args[0].equalsIgnoreCase("testvote")) && (sender.hasPermission("dropparty.testvote")))
             voteEventListener.onVotifierEvent(null); // This line is problem #1
            return true;
    Code (Text):
      public void onVotifierEvent(VotifierEvent event){
          Vote v = event.getVote();
        if (VoteCelebration.onlyVoters.booleanValue()){
            Player player = Bukkit.getServer().getPlayer(v.getUsername()); // This line is problem #2, ".getPlayer(v.getUsername());" is underlined in yellow with ".getPlayer" being marked out in yellow also
            if ((player != null) && (player.isOnline())) {
    Please help me
  2. onVotifierEvent(null);

    You're passing null into it and trying to access values from it later on...
  3. So you are passing "null" as an argument and then you ask why you are getting a NullPointerException when you try to use that "null" to get the vote from it?

    Edit: Sniped...
  4. @Lyxnx & @Wout_

    When i take the "null" out of it then another error comes up- The method onVotifierEvent(VotifierEvent) in the type VoteEventListener is not applicable for the arguements ()
  5. I know Java i've just been inactive from coding for a while, thanks for the help ;/

    Would you like to help
  6. Then pass a VotiferEvent reference to it that's not null...
  7. In the event, just add suppresswarnings("deprecation") to the getPlayer method.

    The method is deprecated, but it still works fine.

    As for problem #1, posts above ^
  8. @Lyxnx
    How? Anything i put that isn't "null" doesn't work
  9. What exactly are you trying to accomplish with


    ? This literally does nothing
  10. If i don't put "null" then i get an error
  11. What are you trying to accomplish with that line of code though?
  12. It's suppose to link up both classes so that the command /vc testvote will work
  13. Not sure you can send a legitimate test vote using only Bukkit. Might need some topsite APIs
  14. But how would i fix the problem
  15. Problem #1 that you stated, you can't unless you use some topsite APIs to call a test vote.
  16. @SuperSniper
    The code is setup to make the plugin think someone had just voted, i got that part right the only part i can't get is linking the two classes together
  17. So, it's not a real vote, just to make people think someone voted?
  18. @SuperSniper
    Yes that command just makes the plugin thinks someone voted so that it takes more votes off the countdown until the party
    But the question still remains how can i link the too classes? It's only accepting null but null isn't working
  19. Then just copy and paste your code from the VotifierEvent to the command. There ya go