Constructor not passing YAML config to external class

Discussion in 'Spigot Plugin Help' started by Equinoxel, Jun 23, 2016.

  1. I started a plugin few weeks ago and now it is in the testing phase.
    Unfortunately, the constructor of an external class is not passing corectly the Yaml config through its' parameters from the main class. This was noticed after I debugged it a bit.
    The weird thing here is that another external class works perectly, passing the config into its' constructor and does not nullify it. I got to specify that the config's value is not null inside of it.
     
  2. MiniDigger

    Supporter

    can you show some code?
    what your are saving is that java takes new RandomObject(paramThatIsNotNull) and in the constructor in RandomObject receives paramThatIsNotNull as null? that would be a bug in java and I am really sure that that would be known by now ^^
    you need to make sure that your param is not null.

    also, please take your time when posting your thread, this should be posting in spigot plugin development, not spigot plugin help...
     
  3. What is the difference between those 2 categories? Sorry, I didn't notice.

    No, I do not randomize anything at that point.
    It works with Commands.java, but not with ArenaManager.java
    This is all I can show you:
    Main:
    Code (Text):
      public FileConfiguration getPluginConfig()
       {
         return this.config;
       }
    This method is working for SURE because it is working in the Commands.java class when called.

    ArenaManager:
    Code (Text):
    private Main main;
     
       public ArenaManager(Main plugin)
       {
         this.main = plugin;
       }
    The cool fact, the instructions inside there are executed(debugged and checked), but the "main" variable remains null. Anywhere inside ArenaManager class "main" variable is used NPE error occures. No, it is not caused by any other sort of instructions or variables - I can confirm(again, debugged and checked)...

    Commands:
    Code (Text):
    private Main main;
     
        public Commands(Main plugin)
        {
            this.main = plugin;
        }
    In this class, no errors occure.
     
  4. MiniDigger

    Supporter

    read the descriptions of the categories...
    where do you call the constructor of the arenamanager. because you pass over a null value.
     
  5. Please refresh and read the edited part. Thanks.

    I am using the constructor in the same way I do with the constructor of Commands.java . That constructor is used to pass over the config(to be able to offer values in external class).
     
  6. MiniDigger

    Supporter

    your problem is that the plugin parameter in the constructor of your arena manager is null. if you don't show me how and where you call the constructor you will need to findout yourself why thats the case.
     
  7. I did not invoked them. Please read again why.
     
    #7 Equinoxel, Jun 23, 2016
    Last edited: Jun 23, 2016
  8. I did not invoked the constructor of Commands' class. It is linking the config file (declared in the Main class) to the Commands class(this one works). The constructor in the ArenaManager was coded in the exact same way but it is not working and I don't know why. One of them is working, but the other one does not.

    To be more exact: https://www.spigotmc.org/threads/trying-to-get-config-outside-of-main-class.11686/
     
    #8 Equinoxel, Jun 23, 2016
    Last edited: Jun 23, 2016