java.lang.IllegalArgumentException: File cannot be null

Discussion in 'Plugin Development' started by DJSanderrr, Jan 18, 2013.

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

    DJSanderrr

    hello,

    i got this error,and know what it means and why it is there.
    (i looked at the Tutorials from bukkit for creating a YamlConfig and you need to create a File thats NULL... soo)
    but how do i fix it?

    More info needed? Please say..

    THANKS IN ADVANCE!!
     
  2. Offline

    gomeow

    Sometimes it helps showing the code in question
     
  3. Offline

    DJSanderrr

    Code:
    package me.DJsZ.CommandLogger;
     
    import java.io.File;
    import java.io.InputStream;
    import java.util.Calendar;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerCommandPreprocessEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class CommandLogger  extends JavaPlugin implements Listener {
     
     
        @Override
        public void onEnable(){
         
            if (DataFile == null) {
                DataFile = new File(getDataFolder(), "data.yml");
             
                InputStream defDataStream = this.getResource("data.yml");
                if (defDataStream != null) {
                    YamlConfiguration defData = YamlConfiguration.loadConfiguration(defDataStream);
                 
                    Data = YamlConfiguration.loadConfiguration(customConfigFile);
                    Data.setDefaults(defData);
                }
            }
            if (customConfig == null) {
                this.reloadCustomConfig();
            }
         
         
            getLogger().info("CommandLogger has been succesfull enabled!");
            this.getServer().getPluginManager().registerEvents(this, this);
        }
     
         private FileConfiguration customConfig = null; //here it goes wrong
         private File customConfigFile = null;//here it goes wrong
     
         private FileConfiguration Data = null;//here it goes wrong
         private File DataFile = null;//here it goes wrong
     
     
        public void reloadCustomConfig() {
            if (customConfigFile == null) {
                customConfigFile = new File(getDataFolder(), "config.yml");
            }
            customConfig = YamlConfiguration.loadConfiguration(customConfigFile);
     
            // Look for defaults in the jar
            InputStream defConfigStream = this.getResource("config.yml");
            if (defConfigStream != null) {
                YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
                customConfig.setDefaults(defConfig);
            }
        }
    
     
  4. Offline

    gomeow

    Look at the Bukkit Wiki, there is information on how to do it correctly
     
  5. Offline

    DJSanderrr

    kk thanks i'll look
     
  6. Offline

    Major_Derp

    DJSanderrr
    What about the error message? Can you post it?
     
  7. Offline

    fireblast709

    just put the "customConfigFile == null" block before the "DataFile == null"
     
Thread Status:
Not open for further replies.

Share This Page