Reading from Config produces error

Discussion in 'Plugin Development' started by caldabeast, Jan 17, 2012.

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

    caldabeast

    My configuration setup is not working, and produces a stack trace error to where it reads from the file. If anyone could tell me what I am doing wrong, that would be fantastic!

    The config generator code:
    Code:
    public class olyNauseate extends JavaPlugin{
        PluginDescriptionFile pdfFile = this.getDescription();
        public final Logger logger = java.util.logging.Logger.getLogger("Minecraft");
        public static olyNauseate plugin;
        FileConfiguration config = null;
        File configFolder = new File("plugins", "olyNauseate");
        File configFile = null;
        @Override
        public void onDisable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info("[olyNauseate] Version " + pdfFile.getVersion() + " by CalDaBeast is now diabled.");
        }@Override
        public void onEnable() {
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info("[olyNauseate] Version " + pdfFile.getVersion() + " by CalDaBeast is now enabled.");
            PluginManager pm = getServer().getPluginManager();
            if (!configFolder.exists()) {
                this.logger.info("[olyNauseate] This is your first time loading olyNauseate");
                this.logger.info("[olyNauseate] Generating Configuration File...");
                this.logger.info("[olyNauseate] Thank you for choosing olyNauseate!");
                File configFile = new File(configFolder, "config.yml");
                this.getConfig().set("olyNauseate.listOfRawsToUse", 1);
                this.getConfig().set("olyNauseate.effect.duration", 10);
                this.getConfig().set("olyNauseate.effect.strength", 3);
                this.saveConfig();
    
    and the line that actually gives the stack trace error:
    Code:
    int rawList = config.getInt("olyNauseate.listOfRawsToUse");
    
     
  2. Offline

    wwsean08

    whats the error, my guess is null pointer exception, and it would be happening because the variable config is null, however that line doesn't exist in the code you posted, and so that's just a guess based on the fact that the initial value of config is null and i don't see you changing it in the snippit of code you posted
     
  3. Offline

    caldabeast

    wwsean08 that text is way down in the plugin, but the only thing giving a problem, but the config file *does* have that in it and, as far as i'm aware, is correct for reading off of. It just gives an error when it tries to do such. Do you (or anyone else) know what's wrong?

    The config file
    Code:
    olyNauseate:
      listOfRawsToUse: 1
      effect:
        duration: 10
        strength: 3
    
     
  4. Offline

    coldandtired

    There's a lot of strange and unnecessary code there :)

    //variables
    FileConfiguration config;

    //inside onEnable()
    config = getConfig();

    Done.
     
  5. Offline

    caldabeast

    Thanks!!!
     
  6. Offline

    theguynextdoor

Thread Status:
Not open for further replies.

Share This Page