Weird config error.

Discussion in 'Plugin Development' started by Darkman2412, Dec 10, 2011.

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

    Darkman2412

    Hi!

    My first time trying to use multiple config files. I followed (copy-pasty) this tutorial.
    All the get, save, reload methods are the same.
    The saveCustomConfig() gets reached, but doesn't create/save the file.

    I need to get 3 String lists, but it throws a NPE at the second one.

    Code:
    FileConfiguration recipec = plugin.getRecipeConfig();
    this.plugin.saveRecipeConfig();
    
    List<String> lburnables = recipec.getStringList("burnables");
    List<String> lsmeltables = recipec.getStringList("smeltables"); //NPE here :/
    List<String> lfuels = recipec.getStringList("fuels");
    The config file:
    Code:
    burnables:
        - blabla
        - blabla2
    smeltables:
        - blabla
        - blabla2
    fuels:
        - blabla
        - blabla2
    I find it kinda weird why it doesn't give the NPE on the first getStringList() :/

    Thank you in advance,
    Darkman2412

    Any ideas? :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 22, 2016
  2. Doesn't the config file have to look like this:
    Code:java
    1. burnables:
    2. - blabla
    3. - blabla2
    4. smeltables:
    5. - blabl
    6. - blabla2
    7. fuels:
    8. - blabla
    9. - blabla2

    ?
     
  3. Offline

    Darkman2412

    @Pandemoneus
    No difference, file doesn't get created and NPE.
    Thanks for helping :)
     
  4. Offline

    theguynextdoor

    Try putting something like this at the end of your onEnable()
    Code:java
    1. config.options().copyDefaults(true);
    2. saveConfig();

    And also maybe you could add a default value for each list, in case the config just doesnt like them being empty.
     
Thread Status:
Not open for further replies.

Share This Page