Solved When ever I use "plugin" NullPointerException

Discussion in 'Spigot Plugin Development' started by Snailz, May 27, 2017.

  1. Hey guys,

    When ever I have anything that has "plugin" in it I get a NullPointerException. At first It was happening with my BukkitRunnable(TestTimer) and then I disabled that and now it's happening in another class(GUI).

    Stack Trace(TestTimer): https://hastebin.com/omibupevim.css

    Stack Trace(GUI): https://hastebin.com/gufumejila.css

    Main: https://hastebin.com/eyaxeqeqew.java

    GUI: https://hastebin.com/finafeqoye.java

    TestTimer: https://hastebin.com/tadivitawi.scala

    Config: https://hastebin.com/dageguqutu.coffeescript

    Thanks for helping and if you need to see any more classes just ask!
    ~Snailz
     
  2. Fields are initialized before constructors are called, you're using the plugin field in other fields before the constructor can set the value.
     
  3. To be honest, your code is a real mess..

    For example in your GUI;

    Code (Java):
    if (x <= 0 && x >= 3 || x <= 9 && x >= 12 || x <= 18 && x >= 21 || x <= 27 && x >= 30 || x <= 36 && x >= 39 || x <= 45 && x >= 48){
    The first one means, if X is equal or lower than 0 and if X is equal or greater than 3.. How could that ever be true... The same for the others...

    Seconds, using a Player variable in HashMap... Goodluck with the memory leaks..
    Third, static abuse...

    Fourth, what the heck is this?
    Code (Text):
    this.getCommand("rulesconfirm").setExecutor(new RulesConfirmCommand(this, new GUI(this), new AnswerCheck(this, new GUI(this))));
     

  4. This is the first plugin I have made in like six months. I sorta forgot alot of stuff. As for the GUI I was doing that late at night. Also, just a noob question. What's an alternative to staring players in a hashmap?

    Is there a way to call the constructor before the fields are initialized or do I have to do something else?
     
  5. You need to initialize something before you can use it...
    For alternative, Use UUIDS they cant be changed..
     
  6. ok. By any chance do you know how I could solve my original problem?
     
  7. Initialize before you use it..
     
  8. Simple, just initialize those fields in the constructor itself.
     
  9. Sorry for the late response but thanks, that fixed it. :)