Solved NPE involving config

Discussion in 'Plugin Development' started by Pink__Slime, May 26, 2013.

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

    Pink__Slime

    So I'm not the best with config files and I'm trying to make my kits plugin easier to implement new kits. First step is making a config file and I've already got an error.

    Line 63 in class main is:
    Code:java
    1. public final static List<String> worlds = Main.inst().getConfig().getStringList("worlds");


    Now here's where I think I'm doing it wrong, here's my config.yml

    Code:
    ###############
    # SlimeKits   #
    # Pink__Slime #
    ###############
     
    worlds:
        - pvp
        - example_world
     
    kits:
        archer:
            enabled: true
        tank:
            enabled: false
        turtle:
            enabled: true
        grandpa:
            enabled: true
        knight:
            enabled: true
        creeper:
            enabled: true
        ninja:
            enabled: true
        wither:
            enabled: true
        stomper:
            enabled: true
        angel:
            enabled: true
        soldier:
            enabled: true
        spider:
            enabled: true
        trickster:
            enabled: true
        blaze:
            enabled: true
        dwarf:
            enabled: true
        fisherman:
            enabled: true
        cannon:
            enabled: true
        poseidon:
            enabled: true
        thor:
            enabled: true
     
  2. Offline

    kreashenz

    I think the config part isn't the error. I think it's the Main.inst().
    [EDIT] And your config file isn't set up correctly. Try
    Code:
    worlds:
      - pvp
      - default
    Hopefully that'd work!
     
    lenis0012 likes this.
  3. Offline

    Pink__Slime

    kreashenz
    Changing config to what you said doesn't work. Same error at same line.

    The Main.inst(). is my method for getting a static method for getConfig() because I can't do:
    public final static List<String> worlds = getConfig().getStringList("worlds");

    Unless you can think of another way, I'm out of ideas.
     
  4. Offline

    kreashenz

    Pink__Slime Does it have to be static? Try
    Code:java
    1. private <mainClass> main
    2. public <Class>(<mainClass> main){
    3. this.main = main
    4. }
    5.  
    6. public final List<String> world = main.getConfig().getStringList("worlds");
     
  5. Offline

    Rocoty

    Can we see your inst() method declaration please?
     
  6. Offline

    beastman3226

    It's an NPE meaning that your List, world, is null. It is null because when your code tries to retrieve the stringList from the config it can't find it.

    If you were to make your own method, have it return the value you want already because my guess is your returning JavaPlugin and using its getConfig() method doesn't return your config. So try what kreashenz is or try:

    Code:java
    1. public class PluginMain extends JavaPlugin {
    2. //onEnable
    3. //onDisable
    4. public static FileConfiguration inst(JavaPlugin plugin) {
    5. return plugin.getConfig();
    6. }
    7. }


    Code:java
    1. public class Worlds {
    2. private PluginMain main;
    3. public Worlds(PluginMain main) {
    4. this.main = main;
    5. }
    6. public static final List<String> = main.inst(main).getStringList("worlds");
    7. }
    8.  
     
  7. Offline

    Sagacious_Zed Bukkit Docs

    Make sure you are not calling JavaPlugin's methods before your plugin has been initialized.
     
    ferrybig likes this.
Thread Status:
Not open for further replies.

Share This Page