Issue with config GetKeys?

Discussion in 'Plugin Development' started by Symphonic, Dec 12, 2019.

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

    Symphonic

    Hello everyone! I have come across a peculiar bug in my code which has been slowing me down for the last few days. It seems that this code:

    Code:
    size = plugin.getConfig().getConfigurationSection("points").getKeys(false).toArray().length;
    particularly this:

    Code:
    .getKeys(false)
    I also tried this:

    Code:
    plugin.getConfig().getConfigurationSection("points").getKeys(false).size;
    has been giving me an exception in my console which just says "null" It is odd because when I attach the eclipse debugger, delete this code, run it, and put it back it seems to work as intended. I am using paperspigot #236 server jar. Anyone know what this problem could be? I've definitely narrowed it down to this section of the code because when it's removed it works perfectly.

    Also, any ways I can avoid this by doing something else to get the amount of entries under a section in config.yml?
     
  2. Offline

    KarimAKL

    @Symphonic Could you show your config.yml file? I'm guessing getConfig()#getConfigurationSection("points") is returning null.
     
  3. Offline

    Symphonic

    ohhhhh, but “int” can’t hold null? It definitely has to be that because when I test it with a random number then there’s something in the confit and then it works. Would this be fixed if I did something like if getkeys == null size = 0?
     
  4. Offline

    KarimAKL

    @Symphonic The variable type doesn't have anything to do with the code throwing a NullPointerException.

    You are trying to get a ConfigurationSection named "points" from the config.yml file but, it doesn't exist, and then it returns null. You then try to call a method from something that's null.
     
  5. Offline

    Symphonic

    Doh.

    I figured out what you meant, and fixed it. Thanks!
     
    KarimAKL likes this.
Thread Status:
Not open for further replies.

Share This Page