Solved File cannot be null error on plugin load

Discussion in 'Plugin Development' started by mw3killer, Apr 1, 2013.

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

    mw3killer

    Without a configuration file, when I try to enable the plugin I get this error.

    Code:
    org.bukkit.plugin.InvalidPluginException: java.lang.IllegalArgumentException: File cannot be null
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:182)
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:305)
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:230)
        at org.bukkit.craftbukkit.v1_5_R2.CraftServer.loadPlugins(CraftServer.java:239)
        at org.bukkit.craftbukkit.v1_5_R2.CraftServer.<init>(CraftServer.java:217)
        at net.minecraft.server.v1_5_R2.PlayerList.<init>(PlayerList.java:55)
        at net.minecraft.server.v1_5_R2.DedicatedPlayerList.<init>(SourceFile:11)
        at net.minecraft.server.v1_5_R2.DedicatedServer.init(DedicatedServer.java:105)
        at net.minecraft.server.v1_5_R2.MinecraftServer.run(MinecraftServer.java:379)
        at net.minecraft.server.v1_5_R2.ThreadServerApplication.run(SourceFile:573)
    Caused by: java.lang.IllegalArgumentException: File cannot be null
        at org.apache.commons.lang.Validate.notNull(Validate.java:203)
        at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:170)
        at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:117)
        at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:111)
        at com.mw3killer.nogoditems.MainClass.<init>(MainClass.java:30)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:178)
        ... 9 more
    And here is the top of my code
    Code:
        private Logger log = Logger.getLogger("Minecraft");
        public FileConfiguration cfg;
        boolean confiscated = false; 
        boolean logger = getConfig().getBoolean("logger");
     
        public void onEnable() {
            try
            {
                File file = new File(getDataFolder(),"config.yml");
                cfg = getConfig();
                if(!file.exists())
                {
                    cfg.addDefault("TimeBetweenChecks", 300);
                    cfg.addDefault("message", true);
                    cfg.addDefault("EnchantmentLimit", 5);
                    cfg.addDefault("logger", true);
                    cfg.options().copyDefaults(true);
                    saveConfig();
                    this.log.info("[NoGodItems] No default configuration found. Creating one now.");
                }
            }
            catch(Exception e){ }
            this.log.info("[NoGodItems] Enabled!");
            new AutomaticRemover(this);
        }
    How can I fix this problem? Thanks!
     
  2. I think you can't do this
    Code:
        boolean logger = getConfig().getBoolean("logger");
    Because you can't do getConfig()... until onEnable() is called.
    You have to change it to
    Code:
        boolean logger;
    And do this inside onEnable()
    Code:
    logger = getConfig().getBoolean("logger");
     
  3. Offline

    mw3killer

    I was thinking that was causing the problem but didn't know the fix. I'll try that

    That fixed it. Thanks!

    ~Solved

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
Thread Status:
Not open for further replies.

Share This Page