Solved Configuration section always return null

Discussion in 'Spigot Plugin Development' started by mmuziek, Aug 6, 2018.

  1. hi there. im bouncing on this problem for a while now.
    and i cannot seems to fix it.

    I wanna receive a full configuration sections keys my config is like :
    Code (Text):
          - test product 1
          - product for testcat
          - default
          - '10.5'
          - testcat
          - shows message in chat/I:1
          - CM:hi there
    i currently use the following to find the ID im looking for (the id must be 1 in this case but strange enough it always returns a nullpointer on the getkeys)
    it gets the cat and productid (is the name) from the other function. but it always crashes.
    i tested the cat it gets
    the cat it gets = testcat
    the id it gets = test product 1
    Code (Text):
    public String getproductid (String productid,String cat){
            ConfigurationSection a = pl.getConfig().getConfigurationSection("catproducts." + cat);
                for(String key : a.getKeys(false)) { << here it errors out
                    if (pl.getConfig().getStringList("catproducts." + cat + "." + key + ".base").get(0).equalsIgnoreCase(productid)){
                        return key;
            return "error";
    does anyone know why this happens?
  2. Have you checked that the YAML is valid?
    Otherwise I can only think that somehow the config doesn't contain the configuration you're trying to get. If the 'pl' variable were null, it'd error out a few lines earlier.
    It's probably a good idea to check at the very top of that method whether the configuration section exists with pl.getConfig().contains("catproducts." + cat); -- maybe even print out the 'cat' variable to make sure it's passing in what you expect.
    • Agree Agree x 1
  3. o lol it reversed the arguments. cat was id and id was cat. i rotated it and now it works.
    strange how sometimes u can look for hours just to find the problem when someone else points at it.
    thanks for the open eyes and solution man :)
    • Friendly Friendly x 1