Solved IllegalArgumentException: File cannot be null. Why?

Discussion in 'Plugin Development' started by thefrooh, Nov 21, 2014.

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

    thefrooh

    Hi, I'm making a multiworld spawn plugin for my server, and I get IllegalArgumentException whenever I try to set a spawn. Here's the necessary part of my code:
    Code:java
    1. public static YamlConfiguration yml;
    2. public void onEnable(){
    3. yml = new YamlConfiguration();
    4. File config = new File("plugins/VinoSpawn/config.yml");
    5. try {
    6. yml.load(config);
    7. } catch (IOException | InvalidConfigurationException e) {
    8. e.printStackTrace();
    9. }
    10. loadConfiguration();
    11. this.getCommand("spawn").setExecutor(new AddSpawn(this));
    12. getLogger().info("Betoltve");
    13. }
    14. public void onDisable(){
    15. saveConfig();
    16. }
    17. public void loadConfiguration(){
    18. getConfig().addDefault("worlds","");
    19. getConfig().options().copyDefaults(true);
    20. saveConfig();
    21. }
    22. public void addSpawnToFile(World w, double x, double y, double z){
    23. String path = "worlds."+w.getName();
    24. getConfig().addDefault(path,""); //error thrown here
    25. List<Double> d = new ArrayList<Double>();
    26. d.add(x);
    27. d.add(y);
    28. d.add(z);
    29. getConfig().set(path, d);
    30. System.out.println(w.getName() + " spawn elkeszitve!");
    31. }



    and the calling from the commandexecutor:

    Code:java
    1. Player p = (Player) sender;
    2. VinoSpawn v = new VinoSpawn();
    3. v.addSpawnToFile(p.getWorld(), p.getLocation().getX(), p.getLocation().getY(), p.getLocation().getZ()); //error thrown at this line too
    4.  
    5. return true;


    What can be the problem? I have multiple worlds, that's why I want to programatically generate the config file when adding a spawn to a world which didn't had one yet. I'm thinking of making a for loop which goes through the List<World> of Bukkit.getWorlds() and then put getConfig().addDefault to the loop. Could that work? Or what's causing my error?
     
  2. Offline

    Skionz

    thefrooh Seems like your file is null, what line is the stack-trace pointing towards?
     
  3. Offline

    fireblast709

    thefrooh don't create new instances of your main class.
     
  4. Offline

    thefrooh

    fireblast709 you mean the VinoSpawn v = new VinoSpawn() part?

    Skionz Stack trace:
    Code:
    org.bukkit.command.CommandException: Unhandled exception executing command 'spawn' in plugin VinoSpawn v0.1
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:196) ~[craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCommand(CraftServer.java:542) ~[craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.PlayerConnection.handleCommand(PlayerConnection.java:932) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:814) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInChat.a(PacketPlayInChat.java:28) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInChat.handle(PacketPlayInChat.java:47) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    Caused by: java.lang.IllegalArgumentException: File cannot be null
        at org.apache.commons.lang.Validate.notNull(Validate.java:203) ~[craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:171) ~[craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:118) ~[craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:112) ~[craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at com.ezres.vinospawn.VinoSpawn.addSpawnToFile(VinoSpawn.java:41) ~[?:?]
        at com.ezres.vinospawn.AddSpawn.onCommand(AddSpawn.java:31) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    
     
  5. Offline

    fireblast709

  6. Offline

    Skionz

    Which line is the exception on? We can't find it because we don't have both of your classes.
     
  7. Offline

    thefrooh

    In my first post, I've added comments to the lines which throws exception, there are 2 of it, one is in my main class, where I add a new default value to the world in which the player set a spawn:
    Code:java
    1. getConfig().addDefault(path,"");


    and then when I call it from the other class:
    Code:java
    1. v.addSpawnToFile(p.getWorld(), p.getLocation().getX(), p.getLocation().getY(), p.getLocation().getZ());
     
  8. Offline

    thefrooh

    Solved with a different method (created files for each world using BufferedWriter and Reader).
     
Thread Status:
Not open for further replies.

Share This Page