Solved Getting values from yml file into a String[]

Discussion in 'Plugin Development' started by Blackwing_Forged, Sep 19, 2017.

Thread Status:
Not open for further replies.
  1. My yml file looks like this:

    Code:
    test:
      test2:
      - test 1
      - test 2
      - test 3
      - test 4
      - test 5
      - test 6
    How do i put all the test 1, ect. into a String[]
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Unrelated question why am i getting a nullpointer on this?
    Code:
    ArrayList<String> test = new ArrayList<String>();
            for(String s : diceConfig.getConfigurationSection("dice").getKeys(false))
            {
                test.add(s);
            }
    the file exists and the path exists
     
  4. Offline

    timtower Administrator Administrator Moderator

  5. File diceFile = new File(pl.getDataFolder() + "/dice.yml");
    FileConfiguration diceConfig = YamlConfiguration.loadConfiguration(diceFile);

    EDIT: *facepalm* i was getting the wrong path i should've been doing test not dice

    But now i get an ArrayIndexOutOfBoundsException:

    Code:
    List<String> l = diceConfig.getStringList("dice" + selected);
                    String[] sl = new String[l.size()];
                    sl = l.toArray(sl);
                   
                    System.out.println(sl[1]);
     
    Last edited: Sep 19, 2017
  6. Offline

    timtower Administrator Administrator Moderator

    @Blackwing_Forged Why do you need an array?
    List does the same stuff.
    And sl[1] might not exist
     
  7. @timtower
    I changed it to this and still give me an indexoutofbounds

    List<String> l = diceConfig.getStringList("dice" + selected);
    System.out.println(l.get(1));

    EDIT: i forgot the . in the path .-. i suck lol sorry for the bother
     
  8. Offline

    timtower Administrator Administrator Moderator

    @Blackwing_Forged Then show your config.
    But I assume that you are missing a dot in your path.
     
Thread Status:
Not open for further replies.

Share This Page