Solved 'plugin' variable ALWAYS NULL!

Discussion in 'Plugin Development' started by ZeusAllMighty11, Feb 9, 2013.

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

    ZeusAllMighty11

    Code:
        private Main plugin;
     
        public MoveHandler(Main plugin)
        {
            this.plugin = plugin;
        }
        
        private final DataHandler handler = new DataHandler(plugin);
    
    Whenever I call plugin.getConfig() it always throws an NPE!
    I've been stumped for an hour! WHY!!! :mad:
     
  2. Offline

    RealDope

    Show whole MoveHandler and Main please. I think I know why but need to see Main.

    ZeusAllMighty11

    Well, you're taking too long and it's 3 AM so I'm going to bed. My solution that I'm pretty sure is right:

    I bet you have:

    Code:JAVA
    1.  
    2. package...
    3. imports ....
    4. class ...
    5. MoveHandler blah = new MoveHandler(this);
    6.  
    7. public void onEnable() {
    8. ...
    9. }
    10.  


    You can't use "this" as an argument in init, as "this" hasn't been fully defined yet. You have to do:

    Code:JAVA
    1.  
    2. package...
    3. imports...
    4. class...
    5. MoveHandler blah;
    6. public void onEnable() {
    7. blah = new MoveHandler(this);
    8. }
    9.  
     
  3. Offline

    ZeusAllMighty11

  4. Offline

    Jeyge

    If the error is in the code where you call plugin.getConfig(), you will want to post that code too.
     
  5. Offline

    ZeusAllMighty11

    Fixed. Some reason it just fixed after time.
     
  6. You should still post the code you had because the problem might come back since you obviously don't understand why it happened :p
     
Thread Status:
Not open for further replies.

Share This Page