1.16.5 Getting null error when getting list from config?

Discussion in 'Spigot Plugin Development' started by Bluehawk409, Jun 21, 2021.

  1. Hello, when I try to read a string list from my config, I get a null error and do not know why. This is my config:
    Code (Text):
      - Test
      - Test2
    And this is my code:
    Code (Text):
    List<String> list = new ArrayList<String>();
                list = plugin.getConfig().getStringList("enchants.SWORD");
    I don't see why it is giving me a null error, any ideas?
  2. Is the config created in your plugin's data folder? Make sure #saveDefaultConfig is called somewhere when your plugin enables.
    • Like Like x 1
  3. Yes, the file is there and I have the save default config on my OnEnable event
  4. Can you share your whole onEnable method?
  5. How about showing the stacktrace to point out what's really returning to null,
    and also you can do this
    Code (Java):
    List<String> list = plugin.getConfig().getStringList("enchants.SWORD");
    without initiating a new arraylist.
    • Agree Agree x 5
  6. I figured it out, needed to refrence it in the main class.
  7. Make a method in your main class called getPlugin or getInstance(). Then, create the instance