Custom YAML file error

Discussion in 'Plugin Development' started by tacticalsk8er, Feb 7, 2013.

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


    OK I have no clue what is wrong with my code, but on the start up of my test server I get this stack trace:
    Stack Trace (open)
    2013-02-07 22:17:50 [SEVERE] Error occurred while enabling Strike v0.1 (Is it up to date?)
    at me.tacticalsk8er.Strike.YAML.saveDefaultConfig(
    at me.tacticalsk8er.Strike.Main.onEnable(
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(
    at org.bukkit.craftbukkit.v1_4_R1.CraftServer.loadPlugin(
    at org.bukkit.craftbukkit.v1_4_R1.CraftServer.enablePlugins(
    at org.bukkit.craftbukkit.v1_4_R1.CraftServer.reload(
    at org.bukkit.Bukkit.reload(
    at org.bukkit.command.defaults.ReloadCommand.execute(
    at org.bukkit.command.SimpleCommandMap.dispatch(
    at org.bukkit.craftbukkit.v1_4_R1.CraftServer.dispatchCommand(
    at org.bukkit.craftbukkit.v1_4_R1.CraftServer.dispatchServerCommand(
    at net.minecraft.server.v1_4_R1.DedicatedServer.r(
    at net.minecraft.server.v1_4_R1.MinecraftServer.q(

    Here is the link to my source code:
    Any advice or suggestions would be appreciated :) Thank you!
  2. I can see what's wrong and you should really learn to go through your program using the information from the stack trace.
    database = new YAML(this, "Database.yml");
    This is called which calls the YAML constructor.
    public YAML(JavaPlugin plugin, String fileName) {
            if (plugin == null)
                throw new IllegalArgumentException("plugin cannot be null");
            if (!plugin.isInitialized())
                throw new IllegalArgumentException("plugin must be initiaized");
            this.plugin = plugin;
            this.fileName = fileName;
    The Constructor finishes but hasn't created or set any useful variables. It hasn't checked if a file exists. Basically, it's done nothing very useful.
    Then this is called as you're trying to save your config.
    public void saveDefaultConfig() {
            if (!configFile[B].exists()[/B]) { 
                this.plugin.saveResource(fileName, false);
    Then you call the .exists method of the configFile variable. configFile is null, you haven't set anything here.

    1. In the YAML constructor you need to add the file checking and creation method calls.
    2. You should almost always check if a variable is null before you try calling any methods.
Thread Status:
Not open for further replies.

Share This Page