Trouble with Config

Discussion in 'Spigot Plugin Development' started by MarkIsCool, Jun 30, 2018.

  1. Config.yml
    Code (Text):

    PrisonMines:
      freshmeat:
        delay: 20
        locations:
          '1':
            x: 690
            y: 73
            z: 740
     
    I am getting the error in this line of code.
    Code (Text):

    ConfigurationSection locations = config.getConfigurationSection("PrisonMines").getConfigurationSection("freshmeat").getConfigurationSection("locations");
     
     
  2. Code (Java):
    ConfigurationSection locations = config.getConfigurationSection("PrisonMines.freshmeat.locations");
     
  3. Hmm, (That solved the error. Thanks so much! But,) I'm getting another error when I try to do
    Code (Text):

    for (String s : locations.getKeys(false)) {
    //do stuff
    }
     
     
  4. Would help to know what these "errors" are.
     
  5. error:
    http://prntscr.com/k18j9r

    Line 81:
    Code (Text):

            for (String s : locations.getKeys(false)) {
     
    Line 64.
    Code (Text):

            registerBlockToConfig(prison, mineblock);
     
    This is simply just calling the method which leads to the error in line 81.

    My Config:
    Line 81 is not able to get the keys from configuration section, locations.
    Code (Text):

    PrisonMines:
      freshmeat:
        delay: 20
        locations:
          '1':
            x: 690
            y: 73
            z: 740

     
     
  6. What is setting your variable "config"? Your "locations" variable is null which is why getKeys is throwing an NPE. This means "config" isnt holding the data you think it is.
     
  7. Try to remove the ' ' in your config
     
  8. Shouldn't be relevant, you can't have numbers on the left hand side of the colon unless they're strings, hence the single quotes.

    Either it's null or config is null, yeah. I agree.