Solved Method reference is null!

Discussion in 'Plugin Development' started by PumpMelon, Oct 1, 2016.

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

    PumpMelon

    Hello,

    Basically when I make the reference call to partyStart(); its null.
    http://hastebin.com/ekonifenag.swift

    I've tried all sorts of things, like setting partyInstance = this; inside of the partyStart(){} but that didn't work.

    Right now my reference calls look like this -
    Code:
    PartyStart.partyInstance.getPartyInstance().partyStart();
    
    Any help is appreciated!
     
  2. Offline

    Zombie_Striker

    @PumpMelon
    I'm assuming you mean that the object returned is not, and not that it is throwing an NPE. Even still, don't abuse static. If you have to, atleast create a getter for the instance. Also, you get the partInstance, just to call "getPartyInstance"? So this means you get the instance so you can get the instance.

    Code:
    
        public static PartyStart partyInstance;
    
        public  PartyStart getPartyInstance(){
            partyInstance = this;
    
            return partyInstance;
        }
    
    The reason it returns a null value is because the instance is never created. To fix this:
    1. Make getPartyInstance static. That should help you understand what your problem is.
    2. Instead of setting "partyInstance" equal to "this "(a non-existant class), set it equal to a new instance of the class.
    3. Only set the instance if it is null. If it is equal to something (not null), there is no reason to set it to anything else.
     
  3. Offline

    PumpMelon

    Thanks! Works well now.
     
Thread Status:
Not open for further replies.

Share This Page