Can't solve NPE with .yml file

Discussion in 'Plugin Development' started by LazerAspect, Oct 28, 2016.

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

    LazerAspect

    What I'm trying to do is get a configuration section and then add it to a set. For example:

    I want to get "item1" and "item2":

    Code:
    kits:
        item1:
        item2:
    Here's my attempt at getting that:

    Code:
    public Set<String> kits;
       
        private static ArenaPVPMain main = ArenaPVPMain.getInstance();
       
        public void createQueues(){
            kits = main.getConfig().getConfigurationSection("kits").getKeys(false);
           
        }
    I'm getting a NPE from this line:
    Code:
    kits = main.getConfig().getConfigurationSection("kits").getKeys(false);
    My actual yml file:

    Code:
    kits:
      kit1: false
      kit2: false
    
    I'm a bit confused as to why it's it's null when it is in the file..
     
  2. Offline

    Zombie_Striker

    @LazerAspect
    Are you sure "main" is not null? Are you sure the configuration section exists?
     
  3. Offline

    LazerAspect

    @Zombie_Striker

    Huh, it looks like main is null. Weird because I am using it in other classes and it isn't causing an issue..
     
  4. Offline

    Zombie_Striker

    @LazerAspect
    It's most likely an issue because it is "static", meaning that it is created before the onEnable is ever called. Remove the static and this should be fine.
     
  5. Offline

    LazerAspect

    @Zombie_Striker

    Hmm, it didn't. I even changed my method of getting an instance of a main class to this and it doesn't work:

    Code:
    private final ArenaPVPMain plugin;
       
        public ArenaPVPQueue(ArenaPVPMain plugin) {
            this.plugin = plugin;
        }
    
    
       
       
        public void createQueues(){
            kits = plugin.getConfig().getConfigurationSection("kits").getKeys(false);
    And then I make plugin = this in the onEnable
     
  6. Offline

    mythbusterma

    @LazerAspect

    You wouldn't have to put anything in onEnable, other than calling this constructor. Are you still having an issue?

    It's likely that that section doesn't exist.
     
  7. Offline

    LazerAspect

    @mythbusterma

    Yes I am still having an issue. I think the issue is plugin is null. I tried calling a function from the main class that simply broadcasted a test message and it said the line calling to that function was null.
     
  8. Offline

    mythbusterma

    @LazerAspect

    You're gonna have to show us more of the code that you're using if you expect us to diagnose the issue.
     
Thread Status:
Not open for further replies.

Share This Page