Solved Int from key is 0(not null)

Discussion in 'Plugin Development' started by pipo3090, Jul 30, 2017.

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

    pipo3090

    When I try to get an int from the config using a for loop and print it, it says 0(not null).
    Here's the code:
    Code:
    ConfigurationSection path = core.getConfig().getConfigurationSection("inv.eten");
           
           
            for(String key : path.getKeys(false)){
               
            int lol = core.getConfig().getInt(path + "." + key);
                p.sendMessage(Integer.toString(lol));
               
            }
    And here is the config
    Code:
    inv:
      eten:
        '297': 10 #the ten is what I want
        '260': 7
    
    If someone knows how to solve this, please leave a reply
     
  2. @pipo3090
    If you try printing out what 'path + "." + key' is equal to, you'd see the error. 'path' is not a string representing the section, it IS the section. If instead of doing core.getConfig().getInt() you do path.getInt() (removing the 'path' and the full stop) you will get what you expect.

    If you're wondering why using the incorrect path didn't return null, it's because ints (or any other primitive) cannot be null, and since the return type is int, they have to return something, even if no entry was found.
     
  3. Offline

    pipo3090

    Thanks, it works! Never thought about those two things.
     
Thread Status:
Not open for further replies.

Share This Page