Main class constructor returns null

Discussion in 'Plugin Development' started by TheKiller53, Oct 3, 2016.

Thread Status:
Not open for further replies.
  1. Hey, my main class constructor is returning null:

    Code:
    private MainClass main;
       
        public RacesUtilities(MainClass main){
            this.main = main;
        }
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    timtower Administrator Administrator Moderator

    @TheKiller53 The main class isn't calling the Util class though.
     
  4. @timtower I added this in onEnable:

    Code:
    new RacesUtilities(this);
    EDIT: Didn't work
     
  5. Offline

    timtower Administrator Administrator Moderator

  6. @timtower the reference to the main class. (The constructor)
     
  7. @TheKiller53
    Constructors don't return anything, though.
     
  8. The reference to my main class, via a constructor, is null.
    @AlvinB
     
  9. @TheKiller53
    Then show us where you call the constructor.
     
  10. @TheKiller53
    You don't call the RacesUtilities constructor in either of those classes.
     
  11. @TheKiller53
    To call the constructor, you do "new RaccesUtilities(..args..)", and I don't see you doing that anywhere in those classes.
     
  12. Offline

    mythbusterma

    @AlvinB

    Constructors return the instance of the class that was created. They just can't have a declared return type, since it is already known.


    @TheKiller53

    You have to save the return of the constructor and use that value. I would recommend learning Java before trying to write plugins.
     
  13. @mythbusterma
    @AlvinB
     
  14. Offline

    Lordloss

    As others said before, learning the basics of java will solve this problem. It is important to understand the functionality of object oriented programming languages.
     
    Zombie_Striker likes this.
  15. Offline

    mythbusterma

    @TheKiller53

    I realize he said that, but I already said that he is wrong. Don't be a smart ass when you don't know what you're talking about.
     
    Zombie_Striker likes this.
  16. @mythbusterma Okay so could you please be specific as to what I should do?
     
  17. Offline

    mythbusterma

    @TheKiller53

    I don't see where you're using this object, so I couldn't tell you.
     
  18. @mythbusterma The constructor is in the RacesUtil class and the reference to it (new RacesUtilities(this); ) is in the MainClass. I use the MainClass instance in the RacesUtil class
     
  19. Offline

    mythbusterma

    @TheKiller53

    I don't see that in the class you posted, and why do you have a "config()" method?
     
  20. @mythbusterma I uploaded the class code to paste bin before adding that code, however it is in the MainClass onEnable() method.
    I was trying to add a config hence the config() method.
     
  21. Offline

    mythbusterma

    @TheKiller53

    I don't see anything like that in the pastebin, you might want to check that.

    Also, then you have a method called config() and a method getConfig(), which return two different things...
     
  22. @TheKiller53
    I think we're just going around in circles here, show us a new pastebin with your updated code.
     
Thread Status:
Not open for further replies.

Share This Page